actionscript-3airflash-cs6animate-cc

Loop animation until button is pressed, but let animation finish


Well I know what I must do, just don't know how.

I know I have to (after make all my animations and whatnot) declare all variables on frame 1(in a seperate time-line), like a=0;b=0...

Then do a gotoandplay at the end of the loop to the begging, with a condition (in frame 120, if a=0 gotoandplay (100) otherwise gotoandplay(15)

And then have a button to change the value of a, so that when the loop meets the conditional it goes to whatever frame I want.

Any pointers? Thanks


Solution

  • So i've taken both of yours suggestions, and did this

    1 animation, with a circle going left and right and a button going from frame 1-20 and text saying "Done" one layer 21

    3 layers : Actions Button Layer 1 (animation layer)

    After that i set on Action frame 1, the code

    var loop:Boolean =true
    

    And on frame 20

    if (loop==true){
            gotoAndPlay(2);
    }else {
    gotoAndStop(21)
    }
    

    Then on the button, did

    btn.addEventListener(MouseEvent.CLICK, buttonClicked, false, 0, true);
    function buttonClicked(e:Event):void {
        loop=false
        }
    

    And it worked. the loop finishes and only then it goes to the 21st frame, and stops there.

    Am i missing something? or is this a good solution? (also, might use this for a menu, with case instead of if's and integer values to jump to which chapter i want)