Imajine Blog Imajine Articles
Contact Me

Drawing with actionscript

This tutorial will teach us on how to draw at runtime using actionscript code.

We will use 'drawing methods' of 'movieclip class' to draw shapes in the SWF file in response to events. The following are the movieclip class drawing methods

  • beginFill( )
  • beginGradientFill( )
  • clear( )
  • curveTo( )
  • endFill( )
  • lineTo( )
  • lineStyle( )
  • moveTo( )

Let's use the above drawing methods to draw some basic shapes like a 'line' and a 'triangle' at runtime

Line

Code to draw line at runtime

Select Frame1 of your Layer1 and paste the below in 'action' panel

this.createEmptyMovieClip("line_mc", 10);
line_mc.lineStyle(5, 0xff0000, 100);
line_mc.moveTo(0, 0);
line_mc.lineTo(200, 100);
line_mc._x = 0;
line_mc._y = 0;

Explanation on the above code

this.createEmptyMovieClip("line_mc", 10);

The above code is used to create an empty movieclip called "line_mc"

line_mc.lineStyle(5, 0xff0000, 100);

This code is used to define line style of  "line_mc" movieclip. The parameters inside the brackets define - line size, line color and line transparency respectively.

line_mc.moveTo(0, 0);

defines 'x' and 'y' co-ordinates from where drawing needs to begin inside the movieclip.

line_mc.lineTo(200, 100);

defines 'x' and 'y' co-ordinates where the drawing needs to end

line_mc._x = 0;
line_mc._y = 0;

defines 'x' and 'y' co-ordinates where 'line_mc' needs to be located on the canvas. 
---------------------------------------------------------------------------------------------------------------------

Code to draw triangle and fill color inside at runtime

Curve 
Select Frame1 of your Layer1 and paste the below in 'action' panel

this.createEmptyMovieClip("triangle_mc", 1);
with (triangle_mc)
{
lineStyle(5, 0xFF00FF, 100);
beginFill(0xFF0000);
moveTo(100, 50);
lineTo(150, 150);
lineTo(50, 150);
lineTo(100, 50);
}


Tags: Actionscript drawing tutorial, as2 drawing tutorial, draw at runtime

Download Free Photo Gallery

Download Free Photo Gallery

You can download Imajine's Scrapbook Photo Gallery absolutely free of cost and to customize , you need no knowledge of Adobe Flash.  Click here to view Scrapbook Photo Gallery / download

Tutorials
Flash Tutorials
Horizontal 3D Carousel
MP3 Player
Scrapbook Photo Gallery
Text Enhancement
Color object
Glow effect using actionscript
Drawing with actionscript
Blur Effect
Load external .mp3 file
Preload external .mp3 file
Sound Controller
Set volume of externally .mp3 file
View MP3 song details
Actionscript blur effect
Actionscript fade in / out effect
Fireworks Tutorials
Custom Stroke
Typography / Ink blot effect
Photograph focus effect
Rainbow Pattern
Inset Text Effect
Fuzzy Light Blending Mode
Little bulb effect
Old paper effect
'Post it' effect
Hand drawn designs
Black/White and Sepia tone
Water color painting effect
Vintage effect on vector graphics
Solid color, black/white
Photoshop Tutorials
Photo editing
Purple Haze

Portfolio

Logos
Website design
CMS Customization
Flash
Web development
Print


Download free textures and patterns and use it for your personal use.

Click here to download Textures and Patterns.

Download free birthday cards

Free Birthday Cards
Click here to view Imajine's free downloadable birthday cards for personal and corporate use. Imajine's birthday cards are in jpeg format so it is faster to download and send in your wishes to your friends and family.
Bookmark and Share Tell a Friend jayanthi.varma@imajine.in  |  © 2008 Imajine