Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Need help with button and motion tween...

New Here ,
Mar 01, 2011 Mar 01, 2011

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]

TOPICS
ActionScript
854
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 01, 2011 Mar 01, 2011

It sounds like instead of having stop(); in the last frame, you need to have...  MovieClip(parent).gotoAndStop(1);

Translate
LEGEND ,
Mar 01, 2011 Mar 01, 2011

How does the player movement happen?  The code you show doeesn't appear to make anything move.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 01, 2011 Mar 01, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 01, 2011 Mar 01, 2011

It sounds like instead of having stop(); in the last frame, you need to have...  MovieClip(parent).gotoAndStop(1);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 02, 2011 Mar 02, 2011

Thanks. That did it!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2011 Mar 02, 2011
LATEST

You're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines