|
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 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.
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 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
|