Drawing and Making Movieclips through ActionScript
In this tutorial you will learn how to make MC’s (MovieClips) through actionscript and how to draw with actionscript so that those MC’s aren’t blank.
First of all, open a new flash document and hit F9 (Window>Actions) to open the actions panel. Insert this code:
root.createEmptyMovieClip("my_mc",getNextHighestDepth());
The createEmptyMovieClip function creates a new blank MC. It has 2 parameters. The first one, a string, is the name for the MC (Its instance name I suppose), so you can refer back to it. The second parameter, a number, is the depth for the MC. I put getNextHighestDepth, which gets the next highest depth so you don’t have to worry about it. Two MC’s can’t have the same depth.
Now, insert this code into the actions panel. This will draw a 25×25 square:
my_mc.lineTo(25,0);
my_mc.lineTo(25,25);
my_mc.lineTo(0,25);
my_mc.lineTo(0,0);
Now if you hit ctrl+Enter you should see a square up in the top left corner of the stage. The first line chooses the style of the line. It has 8 parameters, but we will only worry about the first 3 for now. The first one is the line thickness. If you put 3, the line will be 3 pixels thick. The second parameter is the color of the line. 0xRRBBGG. Black is 0×000000, white is 0xFFFFFF. If you don’t know what a color is, open the color mixer and it will show you something like #CC6633. Just replace the # with 0x and flash will produce that color. The third parameter is the alpha of the line. If this is 0 the line will be completely transparent. If it is 100 it will be solid.
The lineTo function draws a line to the points provided (The first two parameters). The first parameters is the _x coordinate you want it to draw to, the second is the _y coordinate. The line will start at 0,0.
Your shape looks pretty boring at the moment, so why don’t you mess around with the lineStyle and add this the line after you create the MC?
my_mc.beginFill(0x006633,100);
If you test your movie (Ctrl+Enter), your MC should be a greeny color. But drawing squares is pretty boring after a while, so how about a star?
my_mc.beginFill(0×0099CC,100);
my_mc.lineStyle(3,0×0066CC);
my_mc.moveTo(0,50);
my_mc.lineTo(25,0);
my_mc.lineTo(50,50);
my_mc.lineTo(0,15);
my_mc.lineTo(50,15);
my_mc.lineTo(0,50);
If you test your movie (Ctrl+Enter) you should now have a star. I you look at the code, you should see a function I havent used yet, moveTo. You can use it so that the line doesnt start at 0,0. For this I used it so the line would start in the bottom left corner of the MC. It has the same parameters as the lineTo function.
You can apply code to dynamically created MC’s just like any other MC.















hey, nice tute, just what i was looking for at this moment
1.i want to know how to make a circle
2.i figured out an easier way to do it
A:i used the ruler or grid
3.thanks for the cool tutorial:)
Yah good tute.
-
Emanuele Feronato (where I get all my other tutes from) made a great tutorial similar to this.
http://www.emanueleferonato.co.....rs-part-1/
@KIM: Okay, I will look into making circles, but what do you mean you used the ruler and grid?
I copied and pasted the star code but it gave an error.
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 2: ‘)’ or ‘,’ expected
my_mc.beginFill(0×0099CC,100);
Total ActionScript Errors: 1 Reported Errors: 1
What version of flash are you using?
New fighting game! (I’s is posting in this topic because it’s the newest) Anywho. It takes what you’ve taught me and formed an awesome fighting AI.
http://www.deviantart.com/deviation/48469918/
Tell me what you think
Yea, I saw that. Its pretty cool but you need to work on the animation a bit.
Yah, The animation was at best…sloppy. I just wanted to get a workiong fighting engine for a game a friend of mine will animate.
nice tut. can u do tweens with actionscript
Yes.
nice tutorial! =D
luv it!
Hey, I have some stuff I need help with live. So I was wondering if you had AIM or MSN messengers. If you want, but dont want to disclose personal information to the public through a comment, just send it you gamejocky@hotmail.com.
It would help a bunch.
sniper_rifle_048[@]hotmail[.]com
… i’m about to get bored…
can you make a tute on how to make a circle and/or square through action scripts?
Did you read the tutorial?
@KIM: Here is a tutorial on how to draw a circle with actionscript: http://www.actionscript.org/fo.....adid=30328
All you had to do was google for it, so stop bugging awesty.
hey iam back i have been out of luck. my hard drive died so i had to get another computer and get flash. i need help agin i dont have any of my old codeing word documents so i need help recreating my jumping code can you tell me what is wroung with it.
onClipEvent (load) {
j = 0;
c = 1;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
if (c > 0) {
j = -15;
_y -= 6;
c = 0;
}
}
}
onClipEvent (enterFrame) {
if (j > 6) {
j = 6;
}
}
onClipEvent (enterFrame) {
if(_root.ground.hitTest(_x (_width/2),_y,true)){
this._x -= 8;
}
if(_root.ground.hitTest(_x-(_width/2),_y,true)){
this._x = 8;
}
if(_root.ground.hitTest(_x,_y (_height/2),true)){
j = 0;
c = 1;
}else{
j += 1;
this._y += j;
}
if(_root.ground.hitTest(_x,_y-(_height/2),true)){
j = 3;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_x += 8;
_xscale = 100;
_root.guy.gotoAndStop(2);
}else if (Key.isDown(Key.LEFT)) {
_x -= 8;
_xscale = -100;
_root.guy.gotoAndStop(2);
}else{
_root.guy.gotoAndStop(1);
}
}
whenever i paste the code in it says error. how do i fix it?
@Eblup: What is going wrong with the code?
@akskater100: What are the errors you are getting?
thanks a bunches ^^!