• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help with on release gotoAndPlay

Community Beginner ,
May 24, 2012 May 24, 2012

Copy link to clipboard

Copied

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!!!

TOPICS
ActionScript

Views

15.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 24, 2012 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 wh

...

Votes

Translate

Translate
LEGEND ,
May 24, 2012 May 24, 2012

Copy link to clipboard

Copied

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

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 24, 2012 May 24, 2012

Copy link to clipboard

Copied

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

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2012 May 24, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 24, 2012 May 24, 2012

Copy link to clipboard

Copied

Thank you again for helping me learn this.  I am taking an AS3 class next month.

I keep getting the following error now.  I updated the button instance name to lowercase and also gave the movie clip that the button resides in an instance name of disclosuremc.  The movie ends on frame 450 but I want the button to start at frame 400 on the main timeline (scene 1) when clicked on.  All of the other code works fine, it's just the last few lines that deal with the button named closebtn.

TypeError: Error #1009: Cannot access a property or method of a null object reference.

    at Sample_fla::MainTimeline/frame450()

Here is my AS3

stop();

Link_2.addEventListener(MouseEvent.MOUSE_UP, function(event: MouseEvent): void {

var sURL: String;

if ((sURL = root.loaderInfo.parameters.clickTag2)) {

navigateToURL(new URLRequest(sURL), "_blank");

}

});

Link_3.addEventListener(MouseEvent.MOUSE_UP, function(event: MouseEvent): void {

var sURL: String;

if ((sURL = root.loaderInfo.parameters.clickTag3)) {

navigateToURL(new URLRequest(sURL), "_blank");

}

});

Link_4.addEventListener(MouseEvent.MOUSE_UP, function(event: MouseEvent): void {

var sURL: String;

if ((sURL = root.loaderInfo.parameters.clickTag4)) {

navigateToURL(new URLRequest(sURL), "_blank");

}

});

Link_5.addEventListener(MouseEvent.MOUSE_UP, function(event: MouseEvent): void {

var sURL: String;

if ((sURL = root.loaderInfo.parameters.clickTag5)) {

navigateToURL(new URLRequest(sURL), "_blank");

}

});

legal.addEventListener(MouseEvent.CLICK, clickFunction);

function clickFunction(evt:MouseEvent):void {

gotoAndStop(341);

}

replay.addEventListener(MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void

{

     gotoAndPlay(1);

}

disclosuremc.closebtn.addEventListener(MouseEvent.CLICK, onClick2);

function onClick2(event:MouseEvent):void

{

     gotoAndPlay(400);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2012 May 24, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 24, 2012 May 24, 2012

Copy link to clipboard

Copied

Thank you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2012 May 24, 2012

Copy link to clipboard

Copied

LATEST

You're welcome

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines