The free movement of flash making objects

Source: Internet
Author: User
Tags continue cos sin

Many of the friends who learn flash want to master Flash programming to enhance their flash design capabilities. But most of the friends think that flash is difficult and difficult to learn. Today, the author uses a simple Flash programming example to explain how to learn flash programming.

First of all don't be nervous, this example design is very simple, the procedure is not very difficult. In the program, the author has added a note. At the end of the article, I will explain some code use methods. OK, let's make it here.

Effect preview:

Source File Download: Click here to download (3 K, zip compressed file)

1. Press the shortcut key Ctrl+f8 to open the Create new symbol panel and make a movie clip symbol named "lead." As shown in Figure 1.

Figure 1

2. Press the shortcut key ctrl+l to open the library panel and drag the actor component into the scene. As shown in Figure 2.

Figure 2

3. Click on the "lead" component, press the shortcut key F9 Open the Actions panel, enter the following code. As shown in Figure 3.

Figure 3

Object Free Motion Code
Execute code after the movie is loaded
Onclipevent (load) {
Cnum = 10;
s = 3;
}

Continue to execute the code after the movie is loaded
Onclipevent (enterframe) {
my_x = _x;
my_y = _y;
My_theta = _rotation;
Delta_dir = random (2);
if (Delta_dir = = 0) {
Delta_dir =-1;
}
Delta = cnum*delta_dir;
My_theta = My_theta+delta;
My_theta_rad = (MY_THETA*MATH.PI)/180;
new_x = my_x+ (S*math.cos (My_theta_rad));
new_y = my_y+ (S*math.sin (My_theta_rad));
_rotation = My_theta;
if ((new_x>0) && (new_x<300)) {
_x = new_x;
} else {
My_theta = 180-my_theta;
}
if ((new_y>0) && (new_y<300)) {
_y = new_y;
} else {
My_theta =-my_theta;
}
_rotation = My_theta;
}

Well, the test results, you can find the "protagonist" in the scene freely irregular movement. In fact, in this instance, the main thing is to use the Flashas control statements, movie properties, and the Math object.

Onclipevent (movieevent) is a movie control control statement that Movieevent is called an "event" trigger. When an event occurs, executes the statement in curly braces behind the event. Load is the action that is performed when a movie clip is loaded. Enterframe will continue to perform the frame action. In the example, the function of the variable "Cnum" is to control the jitter amplitude of the component. The variable "s" controls the moving amplitude of the component.

In Flash animation design, movie clip properties are often used. In this case, the object is able to move because we have changed its _x,_y,_width,_height four movie clip properties. _x property, the function of the _y property is to set the x,y axis coordinate value of the movie. In addition, the _width property of the movie, the function of the _height property, is to set the width and height of the movie.

The _rotation property in the code can change the angle value of the movie so that the movie rotates. The random () method can return a random number. In general, this method is used in the effect of irregular motion. Math.Cos (), Math.sin () is a method of mathematical objects that calculates and returns the cosine and sine of an angle specified in radians.

In the example, we first use the variable "my_x" and "my_y" to record the object's coordinate value. The value of the variable "Delta_dir" varies randomly between 0 and 2 to allow irregular movement of the object. From the last statement "_rotation = My_theta" function can be known about the role of the variable.

Well, the example of the author is analyzed here. If you want to make your flash design ability to get a qualitative leap, in the improvement of graphic design skills, please strive to improve the Flash programming ability, both indispensable.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.