DEV Community

Kinda
Kinda

Posted on

Learn how to write program easily! - Tutorial 1

Why ActionScript?

This programming language is nice for beginner who want to learn the program logic fun. ActionScript is my first programming language and it is learn by myself. I think it is easy to handle the graphic and animation let's focus on the main program logic.

Step one - Create a new MovieClip
MovieClip is an object. It should be a simple graphic or an animation. In this tutorial we will draw a circle on the MovieClip and use program to add the MovieClip on the screen. Let's do it!

  1. Press Ctrl-F8 to create a new MovieClip
  2. Fill the name: "mc_ball"
  3. Click "Advanced"
  4. Click "Export for ActionScript"
  5. Click "OK" button 1
  6. Draw a circle 2

Step two - Put the MovieClip on the screen via programming

  1. Return to the main screen 3
  2. Select the first frame 4
  3. Press F9 to open "Actions" window
  4. Coding
var ball:MovieClip = new mc_ball();
stage.addChild(ball);
Enter fullscreen mode Exit fullscreen mode

Step three - Let's view the result
Press Ctrl-Enter
5

Learn more about programming!

var ball:MovieClip = new mc_ball();

/*
Do you remember "mc_ball"? This is the name of MovieClip which we created at the step one.

"Export for ActionScript" is very important. 
It cannot use this MovieClip in the programming if you skip this step.

The whole line means create a new MovieClip "mc_ball" and named it "ball" to use in the program.
*/
Enter fullscreen mode Exit fullscreen mode
stage.addChild(ball);

/*
Put "ball" on the screen.

"stage" is a key word represent the root of the screen.
*/
Enter fullscreen mode Exit fullscreen mode

Let the ball on the center of the screen.

var ball:MovieClip = new mc_ball();
ball.x = stage.stageWidth / 2;
ball.y = stage.stageHeight / 2;
stage.addChild(ball);

/*
We can control the "ball" and set x-axis, y-axis to change it's position.

"stage.stageWidth" means screen width.
"stage.stageHeight" means screen height. 
*/
Enter fullscreen mode Exit fullscreen mode

6

Maths
Center x-axis is equal to half of width of stage.
Center y-axis is equal to half of height of stage.
7

Thanks~

Discussion (0)