Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 3 of 3

Thread: Help needed with simple animation

  1. #1

    Help needed with simple animation

    Hi, can someone help me out with the button script for this simple animation?

    The functionality I'm after:

    - play button: click once to start animation. Once it's played through I'd like the car to stop on the last frame so we can see where it's ended up.
    - pause button: click to pause animation (play button will resume animation)
    - forward button: hold down to fastforward animation, release to pause on current frame, prevent from looping back to start after reaching final frame.
    - back button: hold down to rewind animation, release to pause on current frame

    As you can see I'm sort of half way there but struggling with the rest.
    Attached Files Attached Files

  2. #2
    Tompa's Avatar
    Trust me, I'm an engineer
    The orange parts is where I edited:
    pause_btn.addEventListener(MouseEvent.CLICK, onStopClick, false, 0, true);
    play_btn.addEventListener(MouseEvent.CLICK, onPlayClick, false, 0, true);
    function onStopClick(evt:MouseEvent):void {stop();}
    function onPlayClick(evt:MouseEvent):void {play();}
    forward_btn.addEventListener(MouseEvent.MOUSE_DOWN, autoInc);
    forward_btn.addEventListener(MouseEvent.ROLL_OUT, stopChange);
    rewind_btn.addEventListener(MouseEvent.MOUSE_DOWN, autoDec);
    rewind_btn.addEventListener(MouseEvent.ROLL_OUT, stopChange);
    stage.addEventListener(MouseEvent.MOUSE_UP, stopChange);
    function autoInc(mevt:MouseEvent):void {dir=2;
    function autoDec(mevt:MouseEvent):void {dir=1;
    function stopChange(mevt:MouseEvent):void {dir=0;
    var dir:int = 0;
    stage.addEventListener(Event.ENTER_FRAME, carMovement)
    function carMovement(e:Event):void{
            case 0:
                // 0 - Do nothing
            case 1:
                // 1 - Go backwards
            case 2:
                // 2 - Go forward
    Works flawless!

  3. #3
    Tompa thanks so much for your help I really appreciate it

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012