Question

In flash, I created a button and gave the button this code (in AS1-AS2)

on (release)
{
    gotoAndPlay(5);
    tellTarget("/Anim") //'Anim' is just short form for 'an animation'

    {
        gotoAndPlay(5);
    } // End of TellTarget
}

Since you can't give specific buttons actions in AS3, I gave the button an instance name (the buttons instance name is now 'runButton') and then decided to do this in the actions layer.

runButton.addEventListener(MouseEvent.CLICK, startAnimation);


function startAnimation(event:MouseEvent){

    gotoAndPlay(5);
    tellTarget("/Anim")
    {
        gotoAndPlay(5);
    } // End of TellTarget

}

but it is giving me an error saying that a '{' is expected after the

function startAnimation(event:MouseEvent):void{

line and it is saying that there is an unexpected '}' on the last line. Any idea how to fix this?

Note: Anim is a movieclip on the main timeline. When I double click the Anim movieclip, it has it's own timeline. I want that timeline to play along with the main timeline, hence the 'gotoandPlay(5) and then the other gotoAndPlay after doing 'tellTarget(Anim').

Was it helpful?

Solution 4

Okay found the answer, turns out I needed to change

tellTarget("/Anim") //'Anim' is just short form for 'an animation'

{
    gotoAndPlay(5);
} // End of TellTarget

to just

Anim.gotoAndPlay(5)

and it worked.

OTHER TIPS

Use "with" instead of tellTarget. But I do not recommend this at all. Instead:

this[ "/Anim" ].gotoAndPlay(5);

Similar to Discipol's answer though I think you'll need to cast to a movie clip first:

MovieClip(this[ "/Anim" ]).gotoAndPlay(5);

tellTarget is deprecated since Flash 5. (http://help.adobe.com/en_US/as2/reference/flashlite/WS5b3ccc516d4fbf351e63e3d118cd9b5f6e-7a2b.html)

function startAnimation(event:MouseEvent):void{
    runButton.gotoAndPlay(5);

    //that slash in the beginning of name (/Anim) I have no idea what to do with, 
    //basically it used to tell a moveiclip named "/Anim" to "gotoAndPlay" however,
    //that is an invalid name so you probably have to change the name of it inside 
    //Flash unless I'm missing some kind of awesome legacy from old AS1/AS2.
    runButton.Anim.gotoAndPlay(5); 
}
runButton.addEventListener(MouseEvent.CLICK, startAnimation);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top