A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Track if Movie exist

  1. #1
    Member
    Join Date
    Apr 2001
    Location
    Cape Town
    Posts
    99

    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;
    }

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center