tailieunhanh - Học Actionscript 3.0 - p 25
Applied Examples 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 package { import ; import ; import ; import ; public class ColorPickerGraphics extends Sprite { public function ColorPickerGraphics() { var colors:Array = [0xFF0000, 0xFFFF00, 0x00FF00, 0x00FFFF, 0x0000FF, 0xFF00FF, 0xFF0000]; var alphas:Array = [1, 1, 1, 1, 1, 1, 1]; var ratios:Array = [0, 42, 84, 126, 168, 210, 255]; var spectrum:MovieClip = drawGradientBox(100, colors, alphas, ratios); addChild(spectrum); colors = [0x000000, 0x000000]; alphas = [0, 1];. | Applied Examples 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 package import import import import public class ColorPickerGraphics extends Sprite public function ColorPickerGraphics var colors Array OxFFOOOO OxFFFFOO OxOOFFOO OxOOFFFF OxOOOOFF OxFFOOFF OxFFOOOO var alphas Array 1 1 1 1 1 1 1 var ratios Array o 42 84 126 168 21O 255 var spectrum MovieClip drawGradientBox 100 colors alphas ratios addChild spectrum colors 0x000000 0x000000 alphas o 1 ratios o 255 var overlay Sprite drawGradientBox 100 colors alphas ratios deg2rad 90 addChild overlay In addition to the aforementioned arrays the method also requires a size for the artwork 100 for both components and optionally a rotation 90 degrees in the case of the overlay sent to the method in line 28 . The rotation value can be omitted from the method call that creates the spectrum lines 18 and 19 not just because it isn t needed but also because the matrixRotation parameter of the method line 34 has a default value. Lines 35 and 36 create a sprite and reference to its graphics property but the movie clip is not yet added to the display list. Instead it is returned by the method in line 48 and added to the display list by the constructor as discussed previously. Because the gradient data is sent to the method through its parameters all that remains in lines 38 through 41 is to specify a linear gradient create the matrix and modify the matrix with the specified size and rotation if any. The matrix is then applied using the createGradientBox method lines 40 and 41 a 1-pixel black line is specified in line 43 and all the gradient values are passed to the beginGradientFill method in lines 44 and 45. Finally lines 46 through 48 draw the rectangle close the fill and return the sprite to the constructor. NOTE Because the rotation angle is easier to specify in degrees .
đang nạp các trang xem trước