162 | Chapter 4: Decorator Pattern
on time by not sleeping for a week is doubly hopeful, has a triple dose of diligence,
and perhaps a double dose of arrogance.)
Charting souls
Like any of the other design patterns, what you do with the output is up to you.
However, because ActionScript 3.0 is part of Flash, this next implementation shows
how to place the output into different formats with graphic elements. ThegetSoul( )
generates a string, and thegood( )andevil( )methods generate numbers. The string
will be placed in a text field embedded in a movie clip, and the vertical position of
the movie clip will be determined by the values generated by thegood( )andevil( )
methods. To get started, save the script in Example 4-37 in an ActionScript file
namedSoul.as.
Example 4-37. Soul.as
package
{
import flash.display.Sprite;
import flash.display.MovieClip;
public class Soul extends Sprite
{
//Instantiate the two MovieClip objects in
//the Library
var devil:Devil=new Devil( );
var angel:Angel=new Angel( );
public function Soul( )
{
var life:Component=new Jane( );
//Add Good
life=new Courage(life);
life=new Compassion(life);
life=new Hope(life);
//life=new Integrity(life);
life=new Openness(life);
life=new Diligence(life);
life=new Justice(life);
//Add Evil
life=new Malice(life);
life=new Prejudice(life);
//life=new Dogmatisms(life);
life=new Arrogance(life);
//life=new Indifference(life);
//life=new Rage(life);
//life=new Obsfuscation(life);
setAngelDevil(life.good(),life.evil(),life.getSoul( ));
}
private function setAngelDevil(right:Number,wrong:Number,
eternalsoul:String)
{
this.addChild(devil);
this.addChild(angel);
var booWrong:Number=Number(wrong>0);