ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Classes and Document Files Support | 495

The getter/setter functions make it far easier to access and display the available


moves. At the same time, the text fields act as temporary storage of values that can


be placed into variables or parameters.


Button Controls


The class for buttons is made up ofSprite,TextFieldandTextFieldTypeclasses.


Example 13-7 shows the script for the class.


gameInfo.width=70;
gameInfo.height=20;
gameFormat=new TextFormat( );
gameFormat.color=0xcc0000;
gameFormat.font="Verdana";
gameFormat.size=10;
gameInfo.defaultTextFormat=gameFormat;
}
public function setMove(pMove:String)
{
gameInfo.text=pMove;
}
public function getMove( ):String
{
return gameInfo.text;
}
}
}


Example 13-7. MoveButton.as


package
{
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.display.Sprite;


public class MoveButton extends Sprite
{
private var mvBtn:Sprite;
private var id:String;


public function MoveButton(mover:String,btncolor:int)
{
mvBtn=new Sprite( );
this.id=id;
addChild(mvBtn);
mvBtn.buttonMode=true;
mvBtn.useHandCursor=true;
mvBtn.graphics.beginFill(btncolor);
mvBtn.graphics.drawRoundRect(0,0,(mover.length*8),20,5,5);
var mvLbl:TextField=new TextField( );


Example 13-6. DynamicText.as (continued)

Free download pdf