Chapter 2 - LayersActions.swf
In this example, MovieClips (Symbols) are arranged on different layers in the FLA. Top-most layers are drawn last, so they appear in the foreground. The bottom-most layer is drawn first, so it appears in the background.
The example also demonstrates the use of ActionScript to detect and respond to events, such as Mouse clicks and Key strokes. Clicking on the example causes an "explosion" symbol to be added to the scene at the location of the click. Holding down SHIFT while clicking causes a powerup to be added to the scene.
The powerup symbol is loaded dynamically using the built-in MovieClipLoader() class.
The complete example is available in the Downloads Center. The ActionScript code for this example is:
_root.ship.gotoAndStop(1);
_root.ship.hit_target._visible = false;
_root.ship.ship_shield._visible = false;
_root.ship._y = 200;
_root.ship.ship_anim.owner = this;
var readyToShoot:Boolean = true;
doneShooting = function () {
readyToShoot = true;
}
onEnterFrame = function () {
_root.ship._y -= 4;
if (readyToShoot) {
readyToShoot = false;
_root.ship.ship_anim.gotoAndPlay("shoot");
}
if (_root.ship._y < 0) _root.ship._y = 400;
}
onMouseDown = function () {
trace("click: " + _xmouse + ", " + _ymouse);
var depth:Number = this.getNextHighestDepth();
var name:String = "TBD_" + depth;
var newPowerup:MovieClip;
if (Key.isDown(Key.SHIFT)) {
this.createEmptyMovieClip(name, depth);
newPowerup = this[name];
var mcl:MovieClipLoader = new MovieClipLoader();
mcl.loadClip("PowerupTBD.swf", newPowerup);
} else {
this.attachMovie("explosion", name, depth);
newPowerup = this[name];
}
newPowerup._x = _xmouse;
newPowerup._y = _ymouse;
}

