Groups | Blog | Home
all groups > flash actionscript > april 2007 >

flash actionscript : Array access in an object



evil_muffin_man
4/29/2007 4:56:45 PM
I've encountered another problem.

The following code does not mention that I have a MovieClip in the Library set
up with its class as my_class. I drag it onto the stage and name it my_object.
When I try to use the my_array property it does not work.

The class includes a boolean property that works fine, so I concluded that my
arrays must be discombobulated. I also tested a string property and it works.

Plz help? :confused;

/////---------
class my_class extends MovieClip
var my_array:Array;
}
/////---------
//my_object <- is instance of my_class
my_object.my_array[0] = "rasin";
trace(my_object.my_array[0]) // returns undefined. why?
dr_ross
4/30/2007 12:00:00 AM
you've got to instantiate the my_array variable as a Array rather than just typecasting it.

so change
var my_array:Array;
to
var my_array:Array = [];
evil_muffin_man
5/1/2007 11:32:39 PM
Omg. I fiddled with this and apperently did just that. That would explain why
it's doing soemthing now,

It's still not working properly. I have three objects, and I set the first
spot in each to three different things, but when I trace them all of the array
values are set to the same value as the last object. No code modifies them
after they are set. I checked.
evil_muffin_man
5/2/2007 3:59:05 PM
Each object should have a unique array property, but it behaves like the
property is the same for all objects. What I mean is when I change the array at
postion 0 for each object, it acts like I'm modifying the same array value
three times.

Why isn't it independent?
evil_muffin_man
5/3/2007 11:34:28 PM
dr_ross
5/4/2007 12:00:00 AM
evil_muffin_man
5/5/2007 3:16:59 AM
Okee...

The class is shown. There is a movie clip in the library with its class set to
"crate." I drag an instance of this MovieClip into another clip and say the
code following the class. I get "item2" and not "item1."

/////////
class crate extends MovieClip {
var contents:Array = new Array();
}
/////////

crate1_mc.contents[0] = "item1";

crate2_mc.contents[0] = "item2";

trace(crate1_mc.contents[0] ); //< returns "item2." why?
evil_muffin_man
5/6/2007 8:59:03 PM
Having just finished my only AS side project, I will now attempt this the hard
way.

I'm going to create five different string properties for the crate class, and
use those instead.

And if that doesn't work I'll have to go back to that one animation I was
doing.
evil_muffin_man
5/6/2007 9:02:46 PM
AddThis Social Bookmark Button