The following example shows how you can draw shapes in ActionScript 3.0 and ActionScript 2.0 using the drawRect() method (ActionScript 3.0) and the moveTo() and lineTo() methods (ActionScript 2.0).
Full code after the jump.
// ActionScript 3.0 var movieClip:MovieClip = new MovieClip(); movieClip.graphics.beginFill(0xFF0000); movieClip.graphics.drawRect(0, 0, 100, 80); movieClip.graphics.endFill(); movieClip.x = 10; movieClip.y = 10; addChild(movieClip);
To draw the same rectangle in ActionScript 2.0, you would call the graphic functions directly on the MovieClip instance rather than the Graphic object, as seen in the following example:
// ActionScript 2.0 createEmptyMovieClip("movieClip", 0); movieClip.beginFill(0xFF0000); movieClip.moveTo(0, 0); movieClip.lineTo(100, 0); movieClip.lineTo(100, 80); movieClip.lineTo(0, 80); movieClip.endFill(); movieClip._x = 10; movieClip._y = 10;
4 Responses to Drawing shapes using the drawing API in ActionScript 3.0 and ActionScript 2.0
Leave a Reply Cancel reply
Recent Posts
- Getting started with the TLFTextField class in ActionScript 3.0 and Flash CS5
- Adding tick marks to a Slider control in Flash using ActionScript 3.0
- Creating a vertical Slider control in Flash using ActionScript 3.0
- Creating a custom context menu item in Flash using ActionScript 3.0
- Rotating a Sprite object around its x-axis in Flash using ActionScript 3.0 and Flash Player 10
- Detecting when the user changes the color in a ColorPicker control in Flash using ActionScript 3.0
- Getting the currently selected color as a hexadecimal value on a ColorPicker control in Flash using ActionScript 3.0
- Toggling the text field on the ColorPicker control in Flash using ActionScript 3.0
- Creating a vertical Slider control in Flash using ActionScript 3.0
- Setting the number of columns on a ColorPicker control in Flash using ActionScript 3.0
Categories
- Bitmap (1)
- Components (72)
- Button (19)
- CheckBox (2)
- ColorPicker (6)
- ComboBox (1)
- DataGrid (8)
- FLVPlayback (7)
- Label (9)
- ProgressBar (2)
- Slider (3)
- TextArea (1)
- TextInput (7)
- UILoader (7)
- ContextMenu (1)
- Embed (4)
- ExternalInterface (2)
- Flex (7)
- Font (2)
- General (5)
- Graphics (2)
- JSFL (14)
- Loader (3)
- LoadVars (3)
- Microphone (1)
- migration (12)
- MovieClip (1)
- MovieClipLoader (1)
- Sound (2)
- TextField (1)
- TLFTextField (1)
- TransitionManager (1)
- Tween (1)
- Uncategorized (1)
- URLLoader (4)
- URLVariables (1)
- Video (1)
- XML (2)
Advertising
"No public Twitter messages." — pdehaan


Thanks !! im still a noobie when it comes to creating stuff using pure actionscript in flash, this really helped ^^
Hi Peter,
Im trying to build a network topology diagram in Flex 2.0, using action script 3.0. I am just running out of ideas to make it work. Your suggestions and tips would be very much appreciated. Here is an outline of my application:
1. Drag images from a list onto a canvas.
2. Each image should have a set of properties, which, the image retains even when dropped onto the canvas.
3. When clicked on the image in the canvas, the properties of that image should be displayed in a property panel(like form).
4. Should be able to connect images.
5. Connectors should not be drawn on the images.
6. Each connector should have its own properties, like, which images are connected, ‘from’ which image ‘to’ which image.
7. Should be able to draw arrow heads towards the ‘to’ image of the connector.
Thanks in advance :)
One more question i had in my mind:
Suppose i just drag an image from a list onto a canvas(anywhere on the canvas), i want a rectangle to appear when my mouse goes over the image(MouseOver event) on the canvas. The rectangle should bound the the image, i.e, it shud look like a fence around the image. Which function should i use. Because, i tried to use event.relatedObject.getBounds and getRect() functions. But i got error saying: Cannot access a property or a function of a null object. What am i supposed to do?
i want dat what ever graphics i draw on the canvas they dont get clear is dere any sort of method by which i can do yhis becoz i m using a line whom i hav too move like cursor so, whenever i use graphics.clear() method my all drawing disappers …………….???
if anybody or u hav any suggestions please give mee
Thanks in advance……………..