As3: how to get a MovieClip to stop

actionscript-3flashmovieclip

I'm working on a Flash project where all of my code is in an external Document.as file.

How would I go about setting up an intro MovieClip that runs and finishes before other MovieClips are loaded? What happens right now is that the clip loads along with everything else in the Document class (content, UI… etc). I want the intro clip to run, stop and then continue will the rest of the code in Document.

I've tried using the stop method on the clip but it seems to do nothing, just puts the MovieClip into a playback loop.

Thanks.

Best Answer

In your document class you can access any MovieClip that can be found in the first frame of the timeline. For example a movieclip with the instance name of "myClip", placed in the first frame, you gain access to it with the following code:

package  
{
    import flash.events.Event;
    import flash.display.MovieClip;

    public class Document extends MovieClip 
    {
        public var myClip:MovieClip;

        public function Document()
        {
            addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event) : void 
        {
            myClip.stop();
        }
    }
}

On the other hand you can access you document class scope from your timeline in flash. Calling a public function defined at you Document "functionAtDocument" would look like so:

Document(this).functionAtDocument();

The code in your Document class:

package  
{
    import flash.display.MovieClip;

    public class Document extends MovieClip 
    {
        // ... missing some code
        public function tracer():void
        {
            trace ('call from flash timeline');
        }
    }
}

With this in mind I thing you can go back and forward, sending values from timeline to the class, and manipulate any movieclip that lives there.

Related Topic