A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Starting and Stopping an Animation using buttons

  1. #1
    Mew!
    Join Date
    Jan 2007
    Location
    Highland Heights, Ohio
    Posts
    5

    Angry Starting and Stopping an Animation using buttons

    Hello,

    I know I've been a member here for quite a while (your resources are wonderful!!), and I apologize for this being my first post. I'm working on an assignment for a Flash Game Programming class (1 of 2) where I have to take a pre-made animation, add start and stop buttons to it, and use AS3 to make those buttons work. I got the buttons on the .fla, but I'm having a heck of a time stopping the animation using the stop button (I haven't even done the start button yet). This course is an independent study so I'm not being "taught" anything by the instructor. I have to find the answers myself. I've asked said instructor, my former AS instructor, and several computer lab monitors for help and we cannot get the animation to work correctly. There are compile errors that come up that really make no sense. Please help! This is my last resort in regards to this assignment!

    Assign1WalkCycle

    Code:
    function onTimerStart(evt:TimerEvent):void
    {
    play();
    }
    stop();
    var timer:Timer = new Timer(2000, 1);
    timer.addEventListener(TimerEvent.TIMER, onTimerStart);
    timer.start();
    or

    Code:
    stop();
    var timer:Timer = new Timer(2000, 1);
    timer.addEventListener(
      TimerEvent.TIMER,
      function(evt:TimerEvent):void {
        play();
      }
    );
    timer.start();


  2. #2
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    Well allow me to be your teacher for a minute.

    You've got a new keyframe for each button on each frame. That can cause problems, because if you set your keyframes first and then try to add actions to the buttons, Flash could lose the actions from frame to frame.

    Second, you're trying to set an action for "stop_mc", which is the name of the item in the library, but Flash completely ignores those names. You instead need to give the button a name in the Properties panel, where it says instance name.

    Third, you're mixing Actionscript 2 and Actionscript 3, which are quite different. If you want to use Actionscript 3, you need to go into File>Publish Settings and tell Flash to use Actionscript 3. And, if you use Actionscript 3, you can't set an action on a button like:

    Code:
    stop_mc.onPress = function()
    {
    	gotoAndPlay(1);
    }
    You instead need to do something like:

    Code:
    stop_mc.addEventListener(MouseEvent.CLICK, functionName);
    Then you need a function like:

    Code:
    function functionName(e:MouseEvent){
       play();
    }
    Finally, you've got a lot of repetitive code. If you want the same code to repeat, it's a better idea to set up a function and call that function instead.

    http://www.richarddoyle.net/tests/fl...rected-as3.zip

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center