10.12.2012 Views

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 13-6. DynamicText.as (continued)<br />

}<br />

}<br />

gameInfo.width=70;<br />

gameInfo.height=20;<br />

gameFormat=new TextFormat( );<br />

gameFormat.color=0xcc0000;<br />

gameFormat.font="Verdana";<br />

gameFormat.size=10;<br />

gameInfo.defaultTextFormat=gameFormat;<br />

}<br />

public function setMove(pMove:String)<br />

{<br />

gameInfo.text=pMove;<br />

}<br />

public function getMove( ):String<br />

{<br />

return gameInfo.text;<br />

}<br />

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

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

be placed into variables or parameters.<br />

Button Controls<br />

The class for buttons is made up of Sprite, TextField and TextFieldType classes.<br />

Example 13-7 shows the script for the class.<br />

Example 13-7. MoveButton.as<br />

package<br />

{<br />

import flash.text.TextField;<br />

import flash.text.TextFieldType;<br />

import flash.display.Sprite;<br />

public class MoveButton extends Sprite<br />

{<br />

private var mvBtn:Sprite;<br />

private var id:String;<br />

public function MoveButton(mover:String,btncolor:int)<br />

{<br />

mvBtn=new Sprite( );<br />

this.id=id;<br />

addChild(mvBtn);<br />

mvBtn.buttonMode=true;<br />

mvBtn.useHandCursor=true;<br />

mvBtn.graphics.beginFill(btncolor);<br />

mvBtn.graphics.drawRoundRect(0,0,(mover.length*8),20,5,5);<br />

var mvLbl:TextField=new TextField( );<br />

Classes and Document Files Support | 495

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!