|
-
Script kiddie
[HELP] How to use getDefinitionByName?
What I'm essentially trying to do is turn movieclips into spritesheets of themselves, showing all positions of their rotations. I can do this for one MC, but I'm having trouble scaling it up to work on multiple ones.
Here's (the top of) my code:
PHP Code:
import flash.utils.getDefinitionByName;
var i:int = 0;
var myMCs:Array = ["Test", "Test2"];
var c:MovieClip;
for (i=0; i<myMCs.length; i++) {
c = getDefinitionByName(myMCs[i]) as MovieClip;
addChild(new c());
}
The problem appears to be with the line addChild(new c());.
It should, in theory, take the list of classes inside myMCs and create an instance of each of those classes.
In other words, I want to dynamically add movie clip instances of Test and Test2 (plus any other ones I add later) to the displayList.
The error I get when I try to compile (btw this is in the Flash authoring environment) is:
1180: Call to a possibly undefined method c.
-
Where are your Test and Test2?
-
Senior Member
I think you actually should type c as a Class, not as a MovieClip...not sure this will work, but try:
Code:
import flash.utils.getDefinitionByName;
var i:int = 0;
var myMCs:Array = ["Test", "Test2"];
var c:Class;
for (i=0; i<myMCs.length; i++) {
c = getDefinitionByName(myMCs[i]) as Class;
var d:MovieClip = new c() as MovieClip;
addChild(d);
}
-
Script kiddie
Thanks Josh, that worked!
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
|