Skip to main content
Participant
March 11, 2012
Question

Code on buttons within MC does not work

  • March 11, 2012
  • 1 reply
  • 544 views

(Flash CS5, Actionscript 2.0)

Hello all,

I've been having a very frustrating problem. I have two buttons, one to go to the next scene and one to go to the first scene of my game. The problem I've found is that any code, ANYTHING I put within an on (release) or a buttonname.onRelease = function() in the main timeline does not work at all.

The button states (up, over, down) work and display correctly. When I click, it shows the down state, as it should. However, any code that is on them does not run. currently I have this on the main timeline:

mcname.onEnterFrame = function() {

     button1name.onRelease = function() {

          trace("this should work");

     }

     button2name.onRelease = function() {

          trace("this should work");

     )

)

Neither trace ever shows up. I really want the code to be (on the buttons):

on (release) {

     nextScene();

}

but that just doesn't want to work, no matter if I put _root. or _level0. or whatever before the nextScene tag.

I have tried it many, many other ways as well. I have tried putting this function on the mc, I have put the code directly on the buttons, and NOTHING WORKS. It's very, very frustrating.

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
March 11, 2012

on your main timeline, assign an instance name to your movieclip (eg, mcname) (in the properties panel) and on mc's timeline, assign an instance name to your button (eg, button2name) (again, in the properties panel).

assign labels to the main timeline frames you want use for navigation (eg, "first scene").  on your main timeline you can then use:

mcname.button2name.onRelease=function(){

gotoAndStop("first scene");

}

Participant
March 12, 2012

Thank you for your prompt reply. I've done as you suggested and it still didn't work. I think the problem may stem from the way I set up the stage. I have every movie clip involved in the scene attached to the stage via the attachMovie() actionscript command. That's how I gave them instance names. I'm not sure if that interferes with referencing the buttons. I have the buttons attached like this:

(scoresign is the mc that houses nextlevelbutton and mainmenubutton)

scoresign.attachMovie("nextlevelbutton", "nextlevelbutton", _root.getNextHighestDepth(), {_x:126, _y:300});

scoresign.attachMovie("mainmenubutton", "mainmenubutton", _root.getNextHighestDepth(), {_x:35, _y:300});

I don't know if that's enough to go on, but I appreciate any help you can offer.

kglad
Community Expert
Community Expert
March 12, 2012

i'm assuming your buttons are movieclip buttons.  if so, use:

scoresign.attachMovie("nextlevelbutton", "nextlevelbutton", scoresign.getNextHighestDepth(), {_x:126, _y:300});

scoresign.attachMovie("mainmenubutton", "mainmenubutton", scoresign.getNextHighestDepth(), {_x:35, _y:300});

scoresign.nextlevelbutton.onRelease=function(){

gotoAndStop("first scene");

}

scoresign.mainmenubutton.onRelease=function(){

// do whatever

}