The most commonly used Flash statements _flash as

Source: Internet
Author: User
Tags constant joins
Box_btn.onpress=function () {
Trace ("OK");
};
button instance Name. Event Handling Method =function () {
Processing program
};
For example:
N=1
Box_btn.onrelease=function () {
N=n+1
Trace ("n=" +n);
}
When the button is clicked, the Output window outputs: "n=2"
Onclipevent (load) {
Stop ();
}
These are the event handler functions for the movie clip. The internal of "()" is an event.
In a flash, the second scene is called in the first scene,
To add a button to the place you want to call in the first scene, write the following code on the button:
On (release) {
Telltarget ("_root") {
gotoAndPlay ("mm2", 1);
}
}
Wherein, "mm2" is the name of the MC of the second scene.
On (release) {
Loadmovie ("fz3.swf", 1);
SetProperty ("fz3.swf", _x,100);
SetProperty ("fz3.swf", _y,100);
_root.createemptymovieclip ("card Game");
Mc.loadmovie ("fz3.swf");
mc._x=0;
mc._y=0;
}
FZ3.SWF is the SWF file that needs to be transferred, _x,_y is the axis
Card game is the name of the MC in SWF
The on (release) structure can only be used for buttons,
Several other related uses such as On (press), ON (rollover), on (rollout), ON (DragOver), ON (Dragout), and so on.
2. Else
The IF statement can be extended and the code that uses else to perform the condition is not valid (the comparison expression is false), as follows:
if (x = = 9) {
gotoAndPlay (15);
} else {
gotoAndPlay (16);
}
You can also use the else if statement to push the IF statement one step further, as follows:
if (x = = 9) {
gotoAndPlay (15);
else if (x = = 10) {
gotoAndPlay (16);
else if (x = = 11) {
gotoAndPlay (20);
} else {
gotoAndPlay (25);
}
You can make an if statement as long as you want, or you can use the else if statement to compare other variables, as follows:
if (x = = 9) {
gotoAndPlay (15);
else if (y<20) {
gotoAndPlay (16);
} else {
gotoAndPlay (25);
}
3. Composite comparison
You can judge the values of several comparison expressions in an if statement,
For example, if you want to jump to frame 10th at x 9 and Y at 20 o'clock, you can use the script shown below:
if ((x = = 9) && (y = = 20)) {
gotoAndPlay (10);
}
Logic and operator && joins two comparison expressions together to become a compound expression,
The value of a compound expression is true when the value of all two expressions is true.
Each comparison expression needs to add separate parentheses for the flash to recognize correctly.
Using and to perform logic and operations in earlier versions of Flash is now recommended for no use.
You can also use the logic or operator | | Joins two comparison expressions together to become a compound expression,
The value of a compound expression is true as long as the value of one expression is true. As shown below:
if ((x = = 7) | | | (y = = 15)) {
gotoAndPlay (20);
}
In this script, as long as X is 7 or Y is 15, or both are set, the result is a jump to frame 20th.
The gotoAndPlay command is not executed until both are true.
3.4.6 function
So far, we've put the script in frame 1th of the movie.
If the program is quite complex, and then placed in the same frame, it makes the script look too large.
function allows you to organize code that needs to be reused and placed in the timeline, for example:
function MyFunction (myNum) {
var newnum = mynum+5;
return newnum;
}
The function begins with a keyword function, followed by its name.
Similar to variable names, you can specify your own function name, preferably a function name to make sense.
The parentheses following the function name hold the parameter of the function, and the argument is also a variable whose value is specified when the function is called.
A function can have several arguments, or it can have no parameters. Regardless of any arguments, the function name should be followed by a pair of parentheses.
The part in the curly braces is the function body, and a local variable newnum is created in the function body.
Set the result of Mynum plus 5 to the value of Newnum.
If you pass 10 as a parameter to the function, the value of the Newnum is 15.
The return command is used only in functions, ending a function by using returns and returning the function value.
Here, Newnum is the function value returned with the return command.
To use a function, you need to call it, as follows:
var a = MyFunction (7);
The statement creates a new local variable A, calls the function MyFunction with 7 as a parameter, and returns the result of the function as the value of the variable A.
The called function starts running, creates a local variable mynum, and takes 7 as the Mynum value,
It then executes the code in the body of the function and returns the value 12 of the Newnum to the caller of the function using the return command. At this point, the value of a becomes 12.
The most important function of functions is that it can be reused. The 3 lines of code shown below produce 3 different results:
Trace (MyFunction (3));
Trace (MyFunction (6));
Trace (MyFunction (8));
Run the above code and you will get results 8, 11 and 13.
One advantage of using a function is that you can change only one place in the function, which affects all commands that invoke the function.
For example, change the var newnum = mynum+5 in the function myfunction to var newnum = mynum+7,
The other purpose of the above 3 commands that call the function will be the 10, 13, and 15 point syntax is to specify the properties of the movie clip.
The following statement sets the _alpha (transparency) property of the movie clip mymc to 50%:
Mymc._alpha = 50;
You can also use point syntax in a movie clip to locate a global variable in the root (root).
If you create a global variable Globelvar in the main timeline,
To use this global variable in a movie clip, you can use the following statement:
Trace (_root.globlevar);
Stop: Causes the movie to be stopped in the current frame of the timeline.
Play: Keeps the movie from starting the current frame.
gotoAndStop: Jumps to a specific frame specified with a frame label or frame number and stops.
gotoAndPlay: Jumps to a specific frame specified with a frame label or frame number and continues playing.
NextFrame: Move the movie to the next frame and stop.
Prevframe: Causes the movie to return to the previous frame and stops.
The Stop command is often used in frame actions to stop the movie and wait for user control.
Other commands are often used in the button's event-handling function.
If there is only one argument in the gotoAndPlay command, Flash will assume that it represents a frame;
If there are two parameters, the 1th argument is the scene name, and the 2nd argument represents the frame in the scene.
To locate the upper-level object that contains an object, you can use the keyword _parent.
If a movie clip is contained in the main timeline, the effect of using _parent and _root in a movie clip is the same.
If the movie clip differs two levels from the main timeline, that is, when the movie clip is contained in another movie clip that is in the main timeline,
When you use _parent in the movie clip, you refer to it as a movie clip at the top level.
And _root refers to its two-level master timeline. _parent cannot be used in the main timeline because the main timeline has no previous level.
9. Learn more about GOTO statements
Prevframe ()
Jump to and stop in front of the last one.
NextFrame ()
Jump to and stop the next one.
Prevscene ()
Jumps to and stops at frame 1th in the previous scene.
Nextscene ()
Jumps to and stops frame 1th in the next scene.
gotoAndPlay ([Scene,] frame)
Jumps to the scene scene (omitting the frame frame that represents the current scene) and plays it.
gotoAndStop ([Scene,] frame)
Jumps to the scene scene (omitting the frame frame that represents the current scene) and stops.
10, to understand the various properties of the MC can be rewritten
_x Center Point relative to x coordinate (pixel unit)
_y Center point relative y-coordinate (pixel unit)
_xscale horizontal scaling, initially 100
_yscale vertical scaling, initially 100
_rotation Relative rotation angle (degree unit)
_width relative display width (pixel units)
_height relative display height (pixel units)
_alpha Display Transparency (0~100)
_visible is visible
_focusrect whether to show the focus box
_name Instance Name
11, three disciplines: 1> write code must be in English (such as en CH) Input method
2> must have a materialistic mind, not loaded MC is not to change its genus
Sex, not to write code to control it. The problem is more difficult to master, and the master sometimes
Offense, the reason is to have to eat before the dinner, nothing to eat what?
3> What you choose to do (in fact, which software does). Add generation to MX
If you do not choose the code, you must specify the name, in fact, is also a kind of first choice.
12, eight note the:1> button cannot be covered with input text, and dynamic text and input text fields cannot be covered with buttons
2> use Loadmoie when LEVEL1 and above files as little as possible with large implicit button
3> Copy a MC instance from a file to another file, copy the frames as much as possible, but not directly
Copy instance,
4> to copy a MC instance from a file to another file, first the character in the target file
There are symbols in the library, loaded into the capital folder, a lot of netizens this question has been excessive?
When you need to remember the role of an action, you can use the comment (note) statement in the Actions panel to add a comment to a frame or button action. If you work in a collaborative environment or provide an example to others, adding a comment can help others to understand the script you are writing.
When you select the comment action in the action panel, the character "//" is inserted into the script. Even more complex scripts are easy to understand if you add comments when you create a script, such as:
On (release) {
Create a new Date object
MyDate = new Date ();
Currentmonth=mydate.getmonth ();
Converts a number of months to a text-represented month
MonthName = Calcmoth (currentmonth);
Year = Mydate.getfullyear ();
currentdate = Mydate.getdat ();
}
Constant
Constants have properties whose values never change. Constants are listed in uppercase letters in the Action Toolbox. For example, constant backspace, ENTER, QUOTE, return, space, and tab are properties of the key object, which refers to the key on the keyboard. To test whether the user is pressing the ENTER key, use the following statement:
if (keycode () = =key. ENTER) {
Alert = "Are you ready?" "
Controlmc.gotoandstop (5);
}

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.