A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: 1 Movieclip starting another AS3

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    13

    1 Movieclip starting another AS3

    Ok so in in the transitional stage to AS3 (still i know)

    I have 2 MovieClips onstage both with a short animation in them. MovieClip2 has the stop(); on its first frame.
    When movieClip1 gets to the end of its timeline I want it to start movieClip2 playing.

    HOW do i do this?

    parent.movieClip2.gotoAndPlay(2); doesnt work.

    DO i need evenetlisteners or something??

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    In your last frame of MC1:
    PHP Code:
    stop();
    dispatchEvent(new Event('mc1Ended')); 
    And in the main timeline (or whatever holds both clips):
    PHP Code:
    movieClip1.addEventListener('mc1Ended'startMC2);

    function 
    startMC2(e:Event):void{
        
    movieClip2.play();
        
    movieClip1.removeEventListener('mc1Ended'startMC2);

    Please use [php] or [code] tags, and mark your threads resolved 8)

  3. #3
    Senior Member
    Join Date
    Aug 2006
    Posts
    322
    Try this
    You don't need to write any code inside of those MovieClip/s. Nor have to give any instance name if all of the MovieClip of the stage will go for nextLoop animation.


    Actionscript Code:
    var arr:Array=new Array();
    var nextIndex:int;

    for (var i=0; i<this.numChildren; i++) {
        arr.push(this.getChildAt(i).name);
        var mc=MovieClip(this.getChildByName(arr[i]));
        mc.stop();
        mc.addEventListener(MouseEvent.CLICK,mouseClickHandler);
    }

    trace(arr);

    function listenHandler(evt:Event):void {
        if (evt.target.currentFrame==evt.target.totalFrames) {
            evt.target.stop();
            MovieClip(this.getChildByName(arr[nextIndex])).play();
            index(MovieClip(this.getChildByName(arr[nextIndex])));
        }
    }
    function mouseClickHandler(evt:MouseEvent):void {
        index(evt.target);
        evt.target.play();
        evt.target.addEventListener(Event.ENTER_FRAME,listenHandler);
    }
    function index(mc) {
        if (arr.indexOf(mc.name)==arr.length-1) {
            nextIndex=0;
        } else {
            nextIndex++;
        }
    }



    marlopax

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