13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Using the drawing API<br />

package{<br />

import flash.display.*;<br />

public class DrawPathExample ext<strong>en</strong>ds Sprite {<br />

public function DrawPathExample(){<br />

}<br />

}<br />

var square_commands:Vector. = new Vector.(5,true);<br />

square_commands[0] = 1;//moveTo<br />

square_commands[1] = 2;//lineTo<br />

square_commands[2] = 2;<br />

square_commands[3] = 2;<br />

square_commands[4] = 2;<br />

var square_coord:Vector. = new Vector.(10,true);<br />

square_coord[0] = 20; //x<br />

square_coord[1] = 10; //y<br />

square_coord[2] = 50;<br />

square_coord[3] = 10;<br />

square_coord[4] = 50;<br />

square_coord[5] = 40;<br />

square_coord[6] = 20;<br />

square_coord[7] = 40;<br />

square_coord[8] = 20;<br />

square_coord[9] = 10;<br />

graphics.beginFill(0x442266);//set the color<br />

graphics.drawPath(square_commands, square_coord);<br />

}<br />

In the above example, each command and coordinate pair is assigned individually to show their position in the array,<br />

but they can be assigned in a single statem<strong>en</strong>t. The following example draws the same star by assigning the values for<br />

each array in a single push() statem<strong>en</strong>t:<br />

package{<br />

import flash.display.*;<br />

public class DrawPathExample ext<strong>en</strong>ds Sprite {<br />

public function DrawPathExample(){<br />

}<br />

}<br />

var square_commands:Vector. = new Vector.();<br />

square_commands.push(1, 2, 2, 2, 2);<br />

var square_coord:Vector. = new Vector.();<br />

square_coord.push(20,10, 50,10, 50,40, 20,40, 20,10);<br />

graphics.beginFill(0x442266);<br />

graphics.drawPath(square_commands, square_coord);<br />

}<br />

Last updated 6/6/2012<br />

236

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

Saved successfully!

Ooh no, something went wrong!