Skip navigation
Slateclean
Currently Being Moderated

If / Then for Buttons to go to Frame Labels?

Jun 23, 2012 6:44 PM

Tags: #problem #button #event #as3.0 #actionscript3 #function #if/then

Hello.

 

I'm asking for some hand-holding on this one. Hopefully I can explain this well enough.

 

I have a complex button that when rolled over the playhead goes to Frame Label textOut.

 

When a roll out is executed, the playhead is to go the Frame Label textIn.

 

Easy enough.

 

 

 

mcBtnHome1.addEventListener(MouseEvent.ROLL_OVER, dropText);
function dropText (evt:MouseEvent): void
{
  mcBtnHome1.gotoAndPlay("textOut");
}

 mcBtnHome1.addEventListener(MouseEvent.ROLL_OUT, raiseText);
function raiseText (evt:MouseEvent): void
{
   mcBtnHome1.gotoAndStop("textIn");
 }


mcBtnHome1.addEventListener(MouseEvent.CLICK, landHome);
function landHome (evt:MouseEvent): void
{
  mcBtnHome1.gotoAndStop("textStay");
 }

 

The problem occurs when I plug in the third event, the click. I click the button, and the playhead moves to Frame Label textStay, as it's supposed to, but once I roll out/ off of the button, the roll out action is again executed. Once I click on the button, no more interaction is supposed to be possible.

 

This happens despite my having a stop(); action at the textStay frame.

 

I'm guessing I need an if / then of if / else statements, with some true / false declarations,  but I've no clue as to what "if's" I should be checking for.

 
Replies
  • Currently Being Moderated
    Jun 23, 2012 7:23 PM   in reply to Slateclean

    In your click function you could remove the ROLL_OUT listener, and then reassign it when you get to your textStay frame.

     

    (Edit - actually, you probably want to assign that ROLL_OUT listener in the ROLL_OVER function at all times)

     

    mcBtnHome1.addEventListener(MouseEvent.ROLL_OVER, dropText);
    function dropText (evt:MouseEvent): void {
         mcBtnHome1.addEventListener(MouseEvent.ROLL_OUT, raiseText);
         mcBtnHome1.gotoAndPlay("textOut");
    }

     

    function raiseText (evt:MouseEvent): void {
         mcBtnHome1.gotoAndStop("textIn");
    }

     

    mcBtnHome1.addEventListener(MouseEvent.CLICK, landHome);
    function landHome (evt:MouseEvent): void {
         mcBtnHome1.removeEventListener(MouseEvent.ROLL_OUT, raiseText);
         mcBtnHome1.gotoAndStop("textStay");
    }

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 24, 2012 5:04 AM   in reply to Slateclean

    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