Flash Tutorials March 21st, 2007
Hi, in this tutorial I will be teaching you how to draw with actionscript. On with the tutorial…
First thing to know is that we don’t need to draw anything, it is just pure actionscript. The first thing we are going to do is make the movie stop on the frame (skip this if you don’t need it) so select the frame you want your drawing to be in, open up the actions panel (F9) and add this code:
Pretty obvious what this does, stops the frame.
Now to make the code easier to manage we will make an empty movieclip. So underneath the stop command in the actions, add this code:
Basically, this creates a movie clip in the root of the movie. When you open the brackets it will promt you for an instance name and the depth. You have to put the instance name in “” marks other it will not work, and because we don’t want this movie clip to appear behind everything else, we use square.getNextHighestDepth() which checks everything for the highest depth and then assigns it to the movieclip.
Now we need to be able to see the movie clip so underneath creating the empty movieclip put this code:
square.lineStyle(4, 333333, 100);
The first line sets the fill; it will prompt you for the colour and the alpha, remember NOT to put the # sign otherwise it will not work, in this case the fill colour is black and the alpha is 100% so you can see it.
The second line sets the line style; it will prompt you to put many things but all you have to do is put the first three: Line thickness, line colour and alpha (in that order). In this case it sets the: Line thickness to be 4, the colour to be dark grey and the alpha to be 100.
Now we need to start drawing. But befor that we must move the movieclip to a different point on the stage (unless you want it in the top-left hand corner) so add the code:
This moves the movieclip that we created earlier to x: 0 and y: 265 (it keeps it at the left but moves it down). Now we are ready to start drawing, so add this code to the actions:
This code just creates a small square.
That concludes the tutorial, I might be extending it at some point but I will leave it for now.
Thanks for reading,