Skip to main content
Participant
June 5, 2016
Answered

AS3 Button inside a movieclip

  • June 5, 2016
  • 2 replies
  • 763 views

As I've only started to learn AS3, I have a really simple question, but I can't figure it out.

I have a movieclip with instance name mcChange, and it has a button inside btnBack. When the button is clicked, I want it to go to the very beginning, to the first frame on the main stage.

I would really appreciate if you could help me with this one.

This topic has been closed for replies.
Correct answer kglad

where's the code located?

if on mcChange's timeline when the button exists:

btnBack.addEventList...

if on the parent timeline of mcChange after mcChange and btnBack exist:

mcChange.btnBack.addEventList...

the code that should be in the listener function depends where the code is located and where the main stage is relative to the code location, though someone is bound to suggest MovieClip(root) to reference the main timeline, which is always poor coding but will often work.

2 replies

Zeeshi_ali_20
Participant
June 7, 2016

change instance property MOVIE CLIP to BUTTON then select last fram of the button and put this code in ACTION area

INSTANCE_NAME.addEventListener(MouseEvent.CLICK,PlayAgain);

function PlayAgain(E:MouseEvent):void

{

  gotoAndPlay(SCENE_NUMBER);

}

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
June 5, 2016

where's the code located?

if on mcChange's timeline when the button exists:

btnBack.addEventList...

if on the parent timeline of mcChange after mcChange and btnBack exist:

mcChange.btnBack.addEventList...

the code that should be in the listener function depends where the code is located and where the main stage is relative to the code location, though someone is bound to suggest MovieClip(root) to reference the main timeline, which is always poor coding but will often work.