Skip navigation
Currently Being Moderated

Help with on release gotoAndPlay

May 24, 2012 9:12 AM

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) {





Thank you!!!

  • Currently Being Moderated
    May 24, 2012 9:42 AM   in reply to mdwebcat

    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 {



    Mark as:
  • Currently Being Moderated
    May 24, 2012 11:07 AM   in reply to mdwebcat

    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

    Mark as:
  • Currently Being Moderated
    May 24, 2012 12:24 PM   in reply to mdwebcat

    If you have new problems you should mark the current posting as answered and start a new posting.


    The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....


    - is declared but not instantiated

    - doesn't have an instance name (or the instance name is mispelled)

    - does not exist in the frame where that code is trying to talk to it

    - is animated into place but is not assigned instance names in every keyframe for it

    - is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).


    If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.

    Mark as:
  • Currently Being Moderated
    May 24, 2012 1:40 PM   in reply to mdwebcat

    You're welcome

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points