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.
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);
Thanks, spoyboyle. Yes, the code isn't formatted well. It was a section of a longer conditional statement that I spent 8 hours trying to work out. I finally just posted this thread at about 4AM out of frustration. I tried to make streamline it, but it just ended up sloppy.
It's prob no surprise that I wasn't able to convey to you exactly what I wanted the code to do
, but still certain segments of your code showed me how to do what I was having trouble with Thanks a lot! I really appreciate it.
North America
Europe, Middle East and Africa
Asia Pacific