// Example: Array of Dynamic Objects package { import flash.display.*; import flash.events.*; import flash.utils.*; public class Wk9ArrayOfDynamicObjects extends MovieClip { // A declaration of an empty array var list: Array = new Array(); // Timer to create a new alien object at each second, // up to 500 maximum var alienTimer: Timer = new Timer(1000, 500); var speed = 5; function Wk9ArrayOfDynamicObjects( ) { alienTimer.addEventListener(TimerEvent.TIMER, addAlien); alienTimer.start(); // Frame event that will move all of the aliens at each frame, // thus animating them stage.addEventListener(Event.ENTER_FRAME, moveAlien) } // end constructor // Create a new alien object of a random size and at a random height // Add the new alien object both to the display list and to the array function addAlien(evt: TimerEvent) { var alien: AlienHead = new AlienHead() alien.height = alien.width = Math.random( ) * 100 + 50 alien.y = Math.random() * 300 + 100 alien.x = 500 addChild(alien) list.push(alien) } // end addAlien // Move all of the aliens 5 pixels to the left function moveAlien(evt: Event) { for( var i = 0; i < list.length; i ++ ) { list[i].x = list[i].x - speed; } } // end moveAlien } }