Flash Advanced Knowledge: Use custom class to implement animation control

Source: Internet
Author: User
Tags definition class definition implement
Advanced | Control This is a high-tech grade test Flash review problem, I did not fully follow the original problem in the production, mainly through this example to learn to "use custom classes to achieve animation control" of some methods on the line.
First, the definition class
Enter the following class definition code in the text editor to save as: human. As class Person {
Attribute definition
var speed: number = 1;
private Var Personso:sound;
Public Function person () {
Personso = new Sound ();
}
The method of moving MC
Public function Move (mc:object, Wheel: Object, Direction: String): Void {
var root = this;
Mc.onenterframe = function () {
if (Direction = = "L") {
if (mc._x<0) {
mc._x = Stage.width; If you are on the left edge of the stage, jump to the right.
}else{
mc._x = root. Speed;
}
Wheel. _rotation-= root, speed;
else if (Direction = = "R") {
if (mc._x>stage.width) {
mc._x = 0;
}else{
Mc._x + = root, speed;
}
Wheel. _rotation + = root speed;
else if (Direction = = "S") {
Delete this.onenterframe;//remove Onenterframe, free memory
}
};
}
Ways to display information
Public function information (): String {
Return ("Let's learn flash! together. ");
}
The way to wave
Public Function Wave (Mc:movieclip, Hsx:boolean): Void {
if (HSX) {
Mc.gotoandplay (2);/wave
} else {
Mc.gotoandstop (1)/Hand down
}
}
Method of sounding
Public function audible (SOU, Port: MovieClip): Void {
Personso.attachsound (SOU);//Load Library Sound
Personso.start ();
The animation of the MC "Kou" while controlling the sound
}
}
A few notes:
1, I used more Chinese variable name, in order to facilitate understanding, so write less notes;
2, about the method (function)--Mobile ()
has three parameters
Move (MC, wheel, direction)
MC to move around the movie clip MC
The movie clip that the wheel wants it to rotate
Direction with string to control the direction of the MC movement: "L" left, "R" to the right, "s" Stop
3, waving the action is essentially the MC itself to complete, the function is only to control the MC jump to the corresponding frame
4, call the sound method has two parameters, the incoming library to link the sound ID name; Mouth action MC's path and MC name.
Second, the production of the scene of the MC and related buttons
For more information look at the source file, the following is the first frame of the source file code:
var myperson = new Person ();
_root.onenterframe = function () {
_ROOT.MOVV = MyPerson. Speed;
}
this. Move left. Onrelease = function () {
MyPerson. Move (_root. Person_mc,_root. PERSON_MC. Wheels, "L");
};
this. Move right. onrelease = function () {
MyPerson. Move (_root. Person_mc,_root. PERSON_MC. Wheel, "R");
};
this. Stop. Onrelease = function () {
MyPerson. Move (_root. Person_mc,_root. PERSON_MC. Wheels, "s");
};
this. Acceleration. onrelease = function () {
if (MyPerson. Speed <100) {
MyPerson. Speed = 1;
}
};
this. Deceleration. Onrelease = function () {
if (MyPerson. Speed >1) {
MyPerson. Speed = 1;
}
};
this. Information. Onrollover = function () {
_root.person_mc.information = MyPerson. Information ();
};
this. Information. Onrollout = function () {
_root.person_mc.information = "";
};
this. Waving. Onrollover = function () {
MyPerson, waving (_root. Person_mc. Right hand, true);
};
this. Waving. Onrollout = function () {
MyPerson, waving (_root. Person_mc. Right hand, false);
};
this. Audible. onrelease = function () {
MyPerson. Audible ("QQ", _root. Person_mc.head);
};

This is being scolded poured post, some people say: fart big an action, wrote N long as.
No way, I'm on this level!
Of course, purely from the realization of the effect, it should be very simple, there is no need to write so many as, but, this is a question:
1, define "class", save as as file. When you click the corresponding button in the class:
1 people move around 2) wave action 3) Audible 4) dynamic text information display and other functions (action)
2, make the corresponding button, the production of PERSON_MC instance MC, and head, body, left hand, right hand, left foot, right foot and dynamic text box into the PERSON_MC.
The action of the mouth and the following wheel is I add, the original problem is not.
This example is not for an effect, but for learning the "class" of an experiment.
Looked, fart big an action, wrote N long as, really must change, please enlighten! Thank you so much!



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.