Okay, this time I am very very confused….

Software: Away3D 4.x

Mr Margaret Scratcher, Sr. Member
Posted: 04 August 2012 02:38 AM   Total Posts: 344

Oky, so I’m trying to create a number of materials and at a certain stage I have

loadImage(material_1face1cubeFaceArray[0].attribute); 

where previously I’ve specified var:material_1:MaterialBase;


so that calls this function:

private function loadImage(targetMattargetFaceimagePath):void
  {
   trace 
("loading image into " targetMat " from " imagePath)
   if (
material_1 == targetMat)
   
{
   trace 
("targetMat is material_1");
   
}

//If I uncomment this, material_1 does not end up as expected
   //targetMat = new ColorMaterial(0x444444);

//If I uncomment this, material_1 does end up as expected   
   //material_1 = new ColorMaterial(0x444444
   
   //TODO this will need to be moved to the LoadSuccess function
   
materialsPrepared += 1;
   if (
materialsPrepared == 6)
   
{
   createMultiCube
();
   
}
   
  } 

but changing ‘targetMat’ from within there, does not seem to change material_1, even thought they are supposed to be the same (you can see I even put a check in there to make sure, and that traces as expected)

However, if I changed material_1 directly in there, then when the face that uses material_1 is made, it does indeed have the correctly coloured face..

Like I say, I am really puzzled by this one..

   

Avatar
theMightyAtom, Sr. Member
Posted: 04 August 2012 05:40 AM   Total Posts: 669   [ # 1 ]

try…

(targetMat as ColorMaterial).color = 0x444444;

Good Luck!

   

Richard Olsson, Administrator
Posted: 04 August 2012 08:42 AM   Total Posts: 1192   [ # 2 ]

What theMightAtom suggested. When you reassign a reference variable that does not update all other references to that object. This is a basic principle of AS3 (and most other programming languages) and nothing that is specific to Away3D.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X