Skip to main content
Known Participant
May 24, 2012
Answered

Help with on release gotoAndPlay

  • May 24, 2012
  • 1 reply
  • 16275 views

Hello -

I am working on a Flash project that was using AS2.  I now need to update it to AS3.  This specific item is for a button that will Close when clicked on and then start playing at frame 400.  The button has an instance name of Close.

Can anyone teach or tell me how to convert the following code to AS3?

on (release) {

    gotoAndPlay(400);

}

Thank you!!!

This topic has been closed for replies.
Correct answer Ned Murphy

If the button is inside a movieclip, then assign an instance name to the movieclip and target the button thru it, for example, if you name the movieclip "mc"...

mc.Closebtn.addEventListener(MouseEvent.CLICK, onClick);

If you intend to learn AS3, one good thing to learn from the start is naming conventions.  Capitalized names are normally associated with class named (just like MovieClip, Button, TextField, etc...)   Instances of objects are normally named starting with lowercase letters.  So for what you show, normally you would use closebtn instead of Closebtn for the instance name.  If you were to assign a class name to the button you would be more likely to call it Closebtn

1 reply

Ned Murphy
Legend
May 24, 2012

In AS3 you need to assign an instance name (shown as objName below)  to the object and use that to target the object via timeline code (or clas file code).

objName.addEventListener(MouseEvent.CLICK, doSomething);

function doSomething(evt:MouseEvent); void {

     gotoAndPlay(400);

}

mdwebcatAuthor
Known Participant
May 24, 2012

Thanks Ned!

I tried something like below but it is not working.  The instance name of my button is Closebtn.  I placed the code below within the Action code on the main timeline where all of my other code resides.  The actual button (Closebtn) is placed within a movie clip.

Closebtn.addEventListener(MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void

{

     gotoAndPlay(400);

}

Ned Murphy
Ned MurphyCorrect answer
Legend
May 24, 2012

If the button is inside a movieclip, then assign an instance name to the movieclip and target the button thru it, for example, if you name the movieclip "mc"...

mc.Closebtn.addEventListener(MouseEvent.CLICK, onClick);

If you intend to learn AS3, one good thing to learn from the start is naming conventions.  Capitalized names are normally associated with class named (just like MovieClip, Button, TextField, etc...)   Instances of objects are normally named starting with lowercase letters.  So for what you show, normally you would use closebtn instead of Closebtn for the instance name.  If you were to assign a class name to the button you would be more likely to call it Closebtn