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.

developed with an eye to the order in which they’ll be placed. We’ll begin with a<br />

look at the Referee class to get an overview and then look at the methods for the<br />

class. Example 13-2 shows the Referee class.<br />

Example 13-2. Referee.as<br />

package<br />

{<br />

//Abstract Class<br />

public class Referee<br />

{<br />

//Move<br />

private var p1Move:String;//Player 1's move<br />

private var p2Move:String;//Player 2's move<br />

private var winner:String;//Value for winner<br />

private var out<strong>com</strong>e:String;//Describe winnder<br />

private var displayWindow:DynamicText;<br />

private var movecheck:Array;//Array to keep track of moves<br />

}<br />

}<br />

//Template Method<br />

final function moveComplete(p1Move:String,p2Move:String,<br />

displayWindow:DynamicText,movecheck:Array):void<br />

{<br />

out<strong>com</strong>e=doWinner(p1Move,p2Move);<br />

displayResults(displayWindow,out<strong>com</strong>e);<br />

resetGame(movecheck);<br />

}<br />

//Abstract methods<br />

protected function doWinner(p1Move:String,p2Move:String):String<br />

{<br />

return winner;<br />

}<br />

function displayResults(displayWindow:DynamicText,<br />

out<strong>com</strong>e:String):void<br />

{<br />

displayWindow.setMove(out<strong>com</strong>e);<br />

}<br />

protected function resetGame(movecheck:Array):void<br />

{<br />

for (var r:uint =0; r< movecheck.length; r++)<br />

{<br />

movecheck[r]=false;<br />

}<br />

}<br />

The <strong>com</strong>ment at the top of the class indicating that the class is an abstract one is simply<br />

a <strong>com</strong>ment. It stands as a reminder that <strong>ActionScript</strong> <strong>3.0</strong> has no real abstract<br />

classes, and we need to remind ourselves to use overrides where needed. Likewise,<br />

The Referee | 479

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

Saved successfully!

Ooh no, something went wrong!