ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Dynamically Changing States | 313

battleUpdate[i].wordWrap=true;
battleUpdate[i].multiline=true;
battleUpdate[i].border=true;
battleUpdate[i].textColor=0xffffee;
scoreFormat=new TextFormat( );
scoreFormat.leftMargin=7;
scoreFormat.rightMargin=7;
getFont (warrior[i].nomDeGuerre);
battleUpdate[i].borderColor=outputColor;
battleUpdate[i].defaultTextFormat=scoreFormat;
battleUpdate[i].text=warrior[i].nomDeGuerre+
":\n"+warrior[i].passOn( );
}
}
//Get the font
private function getFont (creature:String):void
{
switch (creature)
{
case "Earth Fighter" :
outputColor=0xff0000;
scoreFormat.font="Verdana";
break;


case "Android Beam Base" :
outputColor=0x00ff00;
scoreFormat.font="Comic Sans MS";
break;


case "Alien Menace" :
outputColor=0x0000ff;
scoreFormat.font="Arial Black";
break;
}
}
//Get the movie clips from the Library
private function getParts ( ):void
{
//Earthling
earthlingMC=new Earthling( );
addChild (earthlingMC);
earthlingMC.x=60,
earthlingMC.y=120;
missile=new Missile( );
addChild (missile);
missile.x=earthlingMC.x+25;
missile.y=earthlingMC.y+35;
earthlingMC.addEventListener (MouseEvent.CLICK,fireMissile);
earthlingMC.addEventListener
(Event.ENTER_FRAME,earthlingHit);


//Android


Example 8-19. ChangeHandler.as (continued)

Free download pdf