|
-
Pixel Artéést
[RESOLVED] adding variables to movieClips?
Hey,
(Using AS3)
I'm doing a simple grid layout of boxes (movieClips), i'm then trying to save their current position to each of the movieClips.
So in AS2 i'd do something like ...
obj.origX = obj._x;
obj.origY = obj._y;
but it's saying;
1119: Access of possibly undefined property targetX through a reference with static type flash.display isplayObject.
How can i add custom variables to movieClips?
Thanks!
-
Pixel Artéést
The only way i can see to do it at the moment is having another object storing variables like this;
anotherObject["mc"+a+"_"+b+"_x"] = obj.x;
anotherObject["mc"+a+"_"+b+"_y"] = obj.y;
(^ for use in a couple for loops, where a and b are variables to give reference to the movieClips)
What you think? is this the way to do it?
-
MovieClips are dynamic, so you can add properties on the fly like you're trying to do. The error you get indicates that the compiler does not know that the object you are trying to add a dynamic property to is a MovieClip. All it knows is that it's a DisplayObject. DisplayObjects are NOT dynamic, so you can't necessarily add properties. So, to tell the compiler that the object actually is a MovieClip, cast it.
Code:
MovieClip(yourobject).targetX = someValue;
Consider using specific classes that have the properties you want to use defined in the class definition. Not only is it easier from a type-correctness point of view, it is also slightly faster at runtime to find those properties.
-
Pixel Artéést
AAAAAAaaaaaaaahhhh! 
Thanks for that, it alll becomes clear now... haha
Cheers again
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|