- You can use flash. display. Graphics to draw a flex drawing.
The graphics class has a series of functions to create vector graphics. The Display object supports drawing of Sprite and shape objects. These classes contain graphics attributes of the graphics type. For example, the drawrect () function, drawroundrect () (rounded rectangle), drawcircle () (Circular), drawellipse () (elliptical ).
However, graphics objects cannot be directly instantiated from The ActionScript language. An exception is thrown when new is directly used to instantiate graphics objects. The graphics class is final and cannot be inherited.
This attribute is included in Sprite and shape.
For exampleCode:
VaR child: Shape = new SHAPE (); Child. Graphics. beginfill (bgcolor );
Child. Graphics. linestyle (bordersize, Bordercolor ); Child. Graphics. drawroundrect (0, 0, size, size, cornerradius );
Child. Graphics. endfill ();
Addchild (child ); |
This code must be written in the class inherited from displayobjectcontainer.
- In the above example, the class containing graphics objects is used for drawing, and graphics objects are inherited from shape or Sprite. There is also a way to draw an image to a bitmap.
The steps for this method are as follows:
()
Create a bitmapdata object
(B)
Call bitmapdate.
Draw (Source: ibitmapdrawable, matrix: matrix = NULL,
Colortransform: Flash. Geom: colortransform = NULL,
Blendmode: String = NULL,
Cliprect: rectangle = NULL,
Smoothing: Boolean = false): void
In this function, many classes implement the ibitmapdrawable interface, including textfield and graphics.
(C)
Create a bitmap object and use bitmapdata for initialization.
Bitmap(Bitmapdata: bitmapdata = NULL, pixelsnapping: String = "Auto", smoothing: Boolean = false)
(D)
Use displayobjectcontainer and its subclass to call addchild (Child: displayobject): displayobject to add a bitmap object.
Advantages and disadvantages:
Advantage: bitmap is flexible, occupies a small amount of resources, and is fast.
Disadvantage: bitmap has a size limit. So pay attention to it. Otherwise, an exception occurs during running.
In air 1.5 and Flash Player 10, Maximum size for a bitmapdata object is 8,191 pixels in width or height, and The total number of pixels cannot exceed 16,777,215 pixels. (So, if Bitmapdata object is 8,191 pixels wide, it can only be 2,048 pixels high.) in Flash Player 9 and earlier and Air 1.1 and earlier, the limitation is 2,880 Pixels in height and 2,880 pixels in width. If you specify a width or height Value that is greater than 2880, a new instance is not created. |