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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example 13-5. SymPlayer1.as (continued)<br />

}<br />

}<br />

public function setButton( ):void<br />

{<br />

moveBtn=new MoveButton("Make Move",0xcccccc);<br />

moveBtn.name="move";<br />

addChild(moveBtn);<br />

moveBtn.x=100;<br />

moveBtn.y=50;<br />

}<br />

All the text fields and buttons are user classes and they need to be built prior to testing<br />

the class. In the section “Supporting Classes and Document Files” later in the<br />

chapter, you will find the necessary classes for including the buttons and dynamic<br />

text fields.<br />

Move Making<br />

rockBtn=new MoveButton("Rock",0xcccccc);<br />

rockBtn.name="rock";<br />

addChild(rockBtn);<br />

rockBtn.x=100;<br />

rockBtn.y=80;<br />

paperBtn=new MoveButton("Paper",0xcccccc);<br />

paperBtn.name="paper";<br />

addChild(paperBtn);<br />

paperBtn.x=150;<br />

paperBtn.y=80;<br />

scissorsBtn=new MoveButton("Scissors",0xcccccc);<br />

scissorsBtn.name="scissors";<br />

addChild(scissorsBtn);<br />

scissorsBtn.x=200;<br />

scissorsBtn.y=80;<br />

connect=new Connect( );<br />

addChild(connect);<br />

connect.x=175;<br />

connect.y=250;<br />

While the player class may seem fairly long and unwieldy, its key elements are quite<br />

simple. Everything is focused on making one of three moves—rock, paper, or scissors.<br />

Each move is nothing more than a string.<br />

Event to move<br />

The first step is encapsulated in the makeMove( ) function that’s launched by a button<br />

event. Using the name of the button (not the label), an algorithm finds which of the<br />

Player-Proxy Classes | 491

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

Saved successfully!

Ooh no, something went wrong!