Steven Kovar - Interactive Designer

Tech Journal

Latest Entries

Tech and Design

iPhone

Web

Motion

Assigning movie clips levels in Actionscript 3.0

June 04, 2009

I’m relatively new to Actionscript 3.0, but I recently took the pledge that any new projects I build will be in AS 3. Recreating the concepts of AS 2 in AS 3 can be a daunting task. One issue I ran into today, was learning how to assign a stacking order to externally loaded clips.

in Actionscript 2.0, you can load external or library movie clips into levels to create a stacking order of movie clips on the stage. For example, you might have a navigation clip that always loads at the highest level so it remains visible and on top of all other clips. In Actionscript 3.0, level functionality has been removed. In AS 3.0, you can recreate this effect by using setChildIndex. In AS 3, all external content must be loaded into a container and you can then set the z-index of the container. Loading an external swf and setting the z-index of its container is pretty straightforward. In the following example, I’ve created a function that loads an external SWF and assigns it a z-index. I’ve added an Event Listener to a button (actually, a movie clip) on the stage that calls this function when clicked:

function doLoad01(event:Event):void {
    
var request:URLRequest = new URLRequest("myClip.swf");
    var 
ldr01:Loader = new Loader(); //
    
this.addChild(ldr01); // "this" = the stage, the "child" is the loader container
    
this.setChildIndex(ldr0110); //this sets the z-index of the swf's container, "ldr01", to level 10
    
ldr01.contentLoaderInfo.addEventListener(Event.COMPLETEcompleteHandler);
    
ldr01.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESSprogressHandler);
    
ldr01.load(request);

As you can see, the method for loading clips and sending them to levels is pretty straight-forward, but compared to AS 2 has changed quite radically.


Reader Comments


There are no comments yet.

Leave a Comment

Name:

Email:

Url:

Add your comment

Please enter the word you see in the image below: