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

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

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

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

Using the drawing API<br />

var mySprite:Sprite = new Sprite();<br />

mySprite.graphics.beginFill(0xFFCC00);<br />

mySprite.graphics.drawCircle(30, 30, 30);<br />

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

label.width = 200;<br />

label.text = "They call me mellow yellow...";<br />

label.x = 20;<br />

label.y = 20;<br />

mySprite.addChild(label);<br />

this.addChild(mySprite);<br />

Note that the TextField appears on top of the circle drawn with the graphics object.<br />

Creating gradi<strong>en</strong>t lines and fills<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The graphics object can also draw strokes and fills with gradi<strong>en</strong>ts rather than solid colors. A gradi<strong>en</strong>t stroke is created<br />

with the lineGradi<strong>en</strong>tStyle() method and a gradi<strong>en</strong>t fill is created with the beginGradi<strong>en</strong>tFill() method.<br />

Both methods accept the same parameters. The first four are required: type, colors, alphas, and ratios. The remaining<br />

four are optional but are useful for advanced customizing.<br />

The first parameter specifies the type of gradi<strong>en</strong>t you are creating. Acceptable values are Gradi<strong>en</strong>tType.LINEAR or<br />

Gradi<strong>en</strong>tType.RADIAL.<br />

The second parameter specifies the array of the color values to use. In a linear gradi<strong>en</strong>t, the colors will be arranged<br />

from left to right. In a radial gradi<strong>en</strong>t, they will be arranged from inside to outside. The order of the colors of the<br />

array repres<strong>en</strong>ts the order that the colors will be drawn in the gradi<strong>en</strong>t.<br />

The third parameter specifies the alpha transpar<strong>en</strong>cy values of the corresponding colors in the previous parameter.<br />

The fourth parameter specifies ratios, or the emphasis each color has within the gradi<strong>en</strong>t. Acceptable values range<br />

from 0-255. These values do not repres<strong>en</strong>t any width or height, but rather the position within the gradi<strong>en</strong>t; 0<br />

repres<strong>en</strong>ts the beginning of the gradi<strong>en</strong>t, 255 repres<strong>en</strong>ts the <strong>en</strong>d of the gradi<strong>en</strong>t. The array of ratios must increase<br />

sequ<strong>en</strong>tially and have the same number of <strong>en</strong>tries as both the color and alpha arrays specified in the second and<br />

third parameters.<br />

Although the fifth parameter, the transformation matrix, is optional, it is commonly used because it provides an easy<br />

and powerful way to control the gradi<strong>en</strong>t’s appearance. This parameter accepts a Matrix instance. The easiest way to<br />

create a Matrix object for a gradi<strong>en</strong>t is to use the Matrix class’s createGradi<strong>en</strong>tBox() method.<br />

Defining a Matrix object for use with a gradi<strong>en</strong>t<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

You use the beginGradi<strong>en</strong>tFill() and lineGradi<strong>en</strong>tStyle() methods of the flash.display.Graphics class to define<br />

gradi<strong>en</strong>ts for use in shapes. Wh<strong>en</strong> you define a gradi<strong>en</strong>t, you supply a matrix as one of the parameters of these methods.<br />

Last updated 6/6/2012<br />

226

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

Saved successfully!

Ooh no, something went wrong!