-
Track if Movie exist
Can anyone explain to me what am I doing wrong here? The getchildByName value stays null, therefore it is not removing the movieclip.
var myMC:MovieClip;
mybtn.addEventListener(MouseEvent.CLICK,track);
function track(e:MouseEvent):void {
trace(MovieClip(root).getChildByName("myMC"));
if (MovieClip(root).getChildByName("myMC") != null) {
MovieClip(root).removeChild( myMC);
trace("remove");
} else {
trace("add");
myMC=generateMCByString("mySymbol");
MovieClip(root).addChild(myMC);
}
}
function generateMCByString(id:String):MovieClip {
var mcObj:Object = null;
mcObj = getDefinitionByName(id.toString());
return new mcObj as MovieClip;
}
-
First: you did not format your code with [code] tags.
Second: you never assigned a name to your new instance which you assign to myMC. Since you never gave it a name, it's name is something like "instance24" (where the number will change), and not "myMC".
Why are you using getChildByName at all? You know that it will not exist the first time through, and after that, you can just check it directly with contains.
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
|