Copy link to clipboard
Copied
I'm trying to create a simple game. Right now I have one button that when clicked moves the character across the screen. My issue is trying to make the player stop looping after I click the button. If I just insert stop for the last frame it will only loop once and stop, but it will not play again after the button is clicked. I've tried using players_turn boolean but couldn't get that to work. Any help will be appreciated. Thanks!
[AS]
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.ui.Mouse;
public class Main extends MovieClip
{
//Player variables
var players_turn:Boolean = true;
//Enemy variables
public function Main()
{
//Add event listeners
buttonAttack.addEventListener(MouseEvent.CLICK, onButtonAttackClick);
}
//Event handlers
function onButtonAttackClick(event:MouseEvent):void
{
if (players_turn == true)
{
//Player attacks enemy
player.gotoAndStop(2);
trace("attack");
trace(players_turn);
}
}
//trace(players_turn);
/*if (players_turn == false)
{
player.stop();
players_turn = true;
}*/
}
}
[/AS]
It sounds like instead of having stop(); in the last frame, you need to have... MovieClip(parent).gotoAndStop(1);
Copy link to clipboard
Copied
How does the player movement happen? The code you show doeesn't appear to make anything move.
Copy link to clipboard
Copied
player is a symbol that is classic tweened. It has to frames. The first is a still frame with a stop action. The second has been converted as a symbol to show the player move across the screen and back. When the attack button is clicked the player moves across the screen and back but it keeps on looping. If I add a stop action to the last frame it will move and comeback and stop but it will not move anymore when the button is clicked again.
Copy link to clipboard
Copied
It sounds like instead of having stop(); in the last frame, you need to have... MovieClip(parent).gotoAndStop(1);
Copy link to clipboard
Copied
Thanks. That did it!
Copy link to clipboard
Copied
You're welcome
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more