actionscript-3parent-childmovieclip

I can't get MovieClip(parent).play():void; to function correctly


I've been trying to make a parent of my movieclip to run, both via button and frame function. Neither were working. I'd got a warning everytime. This is a simple code I suppose. I never work with as3. But I need this to get done.

Here is what I did. As far as I read, it should be working, it just 1 child really. I use with and without 'this.' function. But nothing's working.

closeBtn.addEventListener(MouseEvent.CLICK, close);

function close(e:MouseEvent):void{
   MovieClip(this.parent).play():void;
}

I expect the parent timeline would play() or gotoandplay() as it should in as2. But I got warning of;

Symbol 'mcSetting_001_bubble', Layer 'ac_', Frame 1, Line 4, Column 33  1078: Label must be a simple identifier.

thank you so much for your help


Solution

  • You shouldn't include :void when calling a function, only when defining one.
    Try changing the code to:

    closeBtn.addEventListener(MouseEvent.CLICK, close);
    
    function close(e:MouseEvent):void{
       MovieClip(this.parent).play();
    }
    

    (1) The compiler picked up the : and thought you were trying to create a label in the code, hence that particular error message.

    (2) Don't use close as a function name since that's already a compiler keyword in AS3 language. Try renaming it to _close or something else. This way it wont clash with AS3's own built-in close.