A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Play a MovieClip from in another Movieclip...

  1. #1
    Senior Member
    Join Date
    Jul 2004
    Posts
    264

    Play a MovieClip from in another Movieclip...

    Hi guys,

    I have 2 movieclips on stage - "clipA" and "clipB"


    Both are animations - at the end of "clipA" - i want to use the AS3 version of _root.clipB.play()

    Then at the end of clipB - i want to use _root.thisFunction()

    To run a function on the stage.


    Thanks for any help!

  2. #2
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    You can do this.

    MovieClip(root).clipB.play();

    and

    MovieClip(root).thisFunction();

  3. #3
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    gasp, technically ok, but bad practice.
    Better to put this on the main timeline:
    Actionscript Code:
    clipA.addEventListener(Event.COMPLETE, onClipAComplete);
    clipB.addEventListener(Event.COMPLETE, onClipBComplete);

    function onClipAComplete(event:Event):void{
      clipB.play();
    }

    function onClipBComplete(event:Event):void{
      thisFunction();
    }

    function thisFunction():void{
      // do stuff
    }

    Then on the last frames of both clipA and clipB, put this:

    Actionscript Code:
    dispatchEvent(new Event(Event.COMPLETE));

  4. #4
    Member
    Join Date
    Jul 2011
    Posts
    51
    @jAQUAN : Please don't mind. I just modified your code a little to make a continuous dispatchEvent.
    Actionscript Code:
    clipA.addEventListener(MouseEvent.CLICK,clickListener);
    clipB.addEventListener(MouseEvent.CLICK,clickListener);

    function clickListener(evt:MouseEvent):void {
        evt.target.addEventListener(Event.ENTER_FRAME,efListener)
        clipA.addEventListener(Event.COMPLETE, onClipAComplete);
        clipB.addEventListener(Event.COMPLETE, onClipBComplete);
        evt.target.play();
    }
    function efListener(evt:Event):void {
        if (evt.target.currentFrame==evt.target.totalFrames) {
            evt.target.dispatchEvent(new Event(Event.COMPLETE));
            thisFunction(evt.target);
        }
    }
    function onClipAComplete(event:Event):void {
        clipB.play();
        clipB.addEventListener(Event.ENTER_FRAME,efListener);
    }
    function onClipBComplete(event:Event):void {
        clipA.play();
        clipA.addEventListener(Event.ENTER_FRAME,efListener);
    }
    function thisFunction(clip):void {
        trace(clip.name);
    }

    @itsallgood : You can even do this by which you can write your code in only one place.


    FFA

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