views:

209

answers:

2

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.

+1  A: 

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.

dome
+1  A: 

You can target the intro MovieClip with a stop action. But I would suggest something like this:

class documentOfFLa extends Sprite {
     public var introMC:MovieClip;           // the introduction animation
     public var restOfAnimation:MovieClip;   // whatever is after the intro
     function documentOfFLa() {              // constructor
          introMC.play();
          restOfAnimation.stop();
     }
     public function continueParent():void {  // call this at end of intro
          restOfAnimation.play();
          introMC.stop();
          removeChild(introMC);
     }
}

...at the end of the intro animation call something like this on the timeline:

this.parent["continueParent"]();

I know this is hack-ish, but it will be quick to implement. Then later you can clean it up...

CJJ