Actionscript 3: targeting issue
- Started
- Last post
- 6 Responses
- CyBrain
I'm looking for a best practice general solution to the way movie clips should be handled. In AS2, you could refer to things in tangible, non-abstract way like
_parent.nav_mc.n1_mc.gotoAndStop...Without going into detail about the type coercion errors I'm getting, I suspect that when you create a new instance of a library symbol with linkage, that you have to do something with it to give it an instance name.
For example, in this scenario:
http://www.kirupa.com/developer/…Suppose I wasn't removing any circles, but wanted to do something to the 25th circle specifically. In this case they all seem to be
"newCircle", which shouldn't be an instance name if they all have it. Did he set it up with 50 instances of "newCircle" or 50 BlueCircle objects that don't have an instance name? In that case how would you give it an instance name?Would something like this have worked?
newCircle.name = "c" + i;Thanks in advance.
- nadnerb0
if they're all in a clip together you could use clip.getChildAt(25);
no need for a name.
If they're named like you mentioned, you can also say
clip.getChildByName("c25");
Here's something though - when you addChild(), it's not automatically typed as a movieclip. you have to define that either in a variable or by casting:
trace(MovieClip(clip.getChildAt...
- nadnerb0
oops
anyway casting is basically saying "this is a movieClip" i.e.
MovieClip(something);
otherwise when they're attached to the stage they just have the type DisplayObject which is where you'd get a type coercion error.
- Awesome answer. I'll let you know if that works. They really love to throw in extra steps to drive you nuts.CyBrain
- acescence0
put them in an array when you create them..
myCircleClips:Array = new Array();
var myCircle:Circle = new Circle();
myCircleClips.push(myCircle);
...
myCircleClips[25].doSomeShit
- nadnerb0
also when you create something you can put it in a variable then you can just refer to it directly.
var theClip = new Whatever();
container.container.addChild(the...MovieClip(theClip).x += 2500;
^ would move the clip. you dont need to path it.
- CyBrain0
Could you also write
var MovieClip(theClip) = new Whatever();
instead of
var theClip = new Whatever();
and having to typecast every mention of theClip like
MovieClip(theClip).x += 2500;
MovieClip(theClip).y += 1000;
etc.?