topical media & game development
actionscript-zoo-VirtualZoo.ax
actionscript-zoo-VirtualZoo.ax
[swf]
flex
Virtual Zoo Example Program, Final Version
from O'Reilly's Essential ActionScript 3.0
by Colin Moock
package {
import flash.display.Sprite;
//import zoo.*;
import flash.events.*;
// The @ax-actionscript-zoo-VirtualZoo class is the main application class. It extends Sprite
// so that it can be instantiated and added to the display list at
// program-start time.
public class @ax-actionscript-zoo-VirtualZoo extends Sprite {
// The VirtualPet instance
private var pet:actionscript_zoo_lib_VirtualPet;
// The object that will render the pet to the screen
private var petView:actionscript_zoo_lib_VirtualPetView;
// Constructor
public function @ax-actionscript-zoo-VirtualZoo () {
// Create a new pet, and attempt to give it a name
try {
pet = new actionscript_zoo_lib_VirtualPet("Bartholomew McGillicuddy");
} catch (e:Error) {
// If attempting to create a VirtualPet object causes an exception,
// then the object won't be created. Hence, we report the problem
// and create a new VirtualPet object here with a known-to-be-valid
// name.
trace("An error occurred: " + e.message);
pet = new actionscript_zoo_lib_VirtualPet("Stan");
}
// Create the object that will render the pet to the screen
petView = new actionscript_zoo_lib_VirtualPetView(pet);
// Register this @ax-actionscript-zoo-VirtualZoo object to be notified when the
// rendering object (the "petView") has finished initializing
petView.addEventListener(Event.COMPLETE, petViewCompleteListener);
}
// An event listener triggered when the VirtualPetView object (petView)
// has finished initializing
public function petViewCompleteListener (e:Event):void {
// Add the view to the display list
addChild(petView);
// Begin the pet's life cycle
pet.start();
// Feed the pet
pet.eat(new actionscript_zoo_lib_Sushi());
}
}
}
(C) Æliens
27/08/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.