Skip navigation
Currently Being Moderated

How can I get this function to fire off last?

Apr 18, 2012 2:29 AM

In the following code, there are two buttons on the stage- "button1" and "button2". 

I want to get the buttons to change frames and THEN have the "playerChange" function fire off.

Currently, the "playerChange" function fires first. Moving the function  either renders the code inoperable or

returns error messages.

 

function buttonChange (e:MouseEvent)

{if    

      

(

                (e.target.currentFrame == "frame1" )

                

                

               

)

     

    {

 

         if (e.target==button1) (playerChange)

                 (e.target.gotoAndStop(player.currentFrame + 1)) 

           else{player.gotoAndStop(player.currentFrame)

           

          if (e.target==button2)  (playerChange) 

                (e.target.gotoAndStop(player.currentFrame + 1))

          else{player2.gotoAndStop(player2.currentFrame)

                   

      }

button1.addEventListener(MouseEvent.CLICK,buttonChange );

button2.addEventListener(MouseEvent.CLICK,buttonChange);

 

Note:this is an abridged version of the code. The code I'm actually using uses 20 buttons and about 8 conditionals for each button, so e.target is more convenient than writing a command for each button.

 
Replies
  • Currently Being Moderated
    Apr 18, 2012 3:09 AM   in reply to witherton

    the code is very hard to understand

     

    it's badly formatted

    {}'s don't match

    you aren't calling a playerChange function

     

    this is my guess at something that might work for you

    function buttonChange (e:MouseEvent)
    {
              if(e.target.currentFrame == "frame1" )
              {
                        if (e.target == button1)
                        {
                                  e.target.gotoAndStop(player.currentFrame + 1);
                                  playerChange();
                        }
                        else
                        {
                                  player.gotoAndStop(player.currentFrame);
                                  if (e.target == button2)
                                  {
                                            e.target.gotoAndStop(player.currentFrame + 1);
                                            playerChange();
                                  }
                                  else
                                  {
                                            player2.gotoAndStop(player2.currentFrame)
                                  }
                        }
              }
    }
    button1.addEventListener(MouseEvent.CLICK,buttonChange );
    button2.addEventListener(MouseEvent.CLICK, buttonChange);
     
     
    
     
    |
    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