One code a day (first part)

Source: Internet
Author: User
Tags case statement continue expression one more line variables rar
A day a code, for beginners is a very good learning opportunities, from shallow into deep, simple and understandable, if you are novice to see it, very good!

First of all, the use of code, it has two kinds of use, one is frame action, one is the object action, frame action is to add code on the frame, object action is in the selected object to add code (said the dish point), how to add code, very simple, frame action is to select that frame and then "window"--> "action", Open the action panel, the left side of the panel is available code, the right side is the code box, that is, display the code you entered, in the Code box above the current code in some parameters. Adding code to an object is also the same operation, selecting the object first, and then doing the same thing as before.

First day, learn two very simple: gotoAndPlay and stop

Stop is one of the most commonly used code in Flash, which is to stop the animation that is currently playing.

gotoAndPlay is also one of the most commonly used code, and its function is to go to and play the specified frame of the specified scene.

The following appendix is a combination of three examples of these two codes.

gotoAndStop

Today we're going to learn gotoandstop.

This code is the same as gotoAndPlay, gotoAndStop is the specified pin to go to and stop the specified scene

Because my computer is broken, I have not installed Flash, so today there is no source file, you can use this code to change yesterday's three source files

Play

This time to learn play

This code should be used almost everywhere, almost every animation will use it

Mostly used in buttons.

Stop

This code is also the most commonly used, but also in almost every animation will be used, its role is to stop the currently playing animation.

Stopallsounds

The purpose of this code is to turn off all the sounds that are playing in the currently playing animation

Button code "on"

Today, learn the button code, but not all, because the button can have a lot of action, this time to learn the button is often used "on"

Its format is:

On (mouse event) {
Statement
}
When you add code to a button in the standard mode of the action panel, the statement in this format automatically appears, and you don't need to add it yourself.

The following are the source files for several mouse events

Annex: On1.rar

Fscommand

We learned the code under "movie Control" in the action panel, from today we'll learn the next unit-"Browser/Network" code, the first is Fscommand
This code specifically I also say is not good, I personally understand is a command to send the code, such as press a button to close the current Flash Play window, this code will use it,

Here's a few source files.

There are only three source files, other options you can do it yourself. What's the effect?

  Note : Exec may not be able to see the effect, its function is in the player to execute the application

Annex: Fscommand.rar

GetURL

This code should not be unfamiliar to everyone.

The purpose of this is to load the specified URL's document (that is, the Web page) into the window

Format:

GetURL ("url", "Window", "variable");

Here are four parameters:

_self: Specifies the current frame of the current window

_blank: Open a new window

_parent: Parent of the current frame

_top: Top frame in the current window

Note : URL must be written in full, such as: http://www.163.com

You must write the http://.

Here are a few source files, you can use these four parameters to go in to try

Annex: Geturl.rar

Loadmoive

Loadmoive, a lot of people in the Empire asked the code how to use, we have to learn a simple

This code is a loading function that loads the specified swf,jpg files into Flash Player

It's format:

Loadmoive ("path or URL to load file", Target/level, variable);

The file to be loaded here must be the same directory as the file you are in, and if not, write the absolute path (what's not right here. Please point out, learn together)

For example, the cc.swf file and your source file can be written in the same directory

Loadmoive ("cc.swf");

If you're not in the same directory, write the path.

Loadmoive ("c:\cc.swf");

Here are two source files, all loaded with cc.swf

Annex: Loadmoive.rar

Loadvariable

This code is similar to the previous loadmoive, is loaded into a file into flash, it loaded with text files, CGI scripts, asp,php, etc.

It's format:

Loadvariables (URL, level, method);

This code I have almost no use, now is learning, so there are a lot of places will not, I hope the master to see this post can be added.

Here's how to use it:

I'm going to use today's source file to explain it, the effect of the source file is to click the button will be in the text box to display a.txt content, then the code to add to the button, in the URL input a.txt, this and Loadmovie, the same is the next to select the "level" rather than "target" (the "target" of this code does not know how to use it)

  Note : The special note here is that the variable name of your text box must be the same as the variable name in the loaded text, I here the text box variable name is output, loaded text file content is OUTPUT=ABC, here ouput is variable name

Here is the source file, let's understand together

Annex: Loadvariable.rar

Unloadmoive

The unloadmoive of learning today is just the opposite of the previous loadmoive, which is unloading files that have already been loaded

Format:

Unloadmoive ("objective");

Other individuals feel that needless to say, the following is a source file, very can explain the problem

Annex: Unloadmoive.rar

Duplicatemovieclip

Today we're going to learn two codes: Duplicatemovieclip and the setproperty below

These two codes are commonly used together (personal thoughts)

First, Duplicatemovieclip.

Its function is to copy movie clips (MC)

Format: duplicatemovieclip (Table of contents, new movie name, level);

The "level" is the duplication of the MC stacking order, low under high, such as the level of 1 is covered by the level of 2 under the MC

SetProperty

Its role is to change the value of a movie's clip when it is played.

Format: setproperty (target, attribute, value/formula);

where "target" means the instance name of the MC for which the attribute is to be changed

"Properties" is the property you want to set

The value/formula is the value of the property to be changed (after the change) or a calculation formula to represent the value.

The following is the source file for the effects of these two codes

Annex: Jinshuai. rar

Onclipevent

The code that you learn today is very familiar, and the previous examples have been used

It is a movie event that executes the following statement when the specified movie event is triggered.

Format:

Onclipevent (movie event) {
Statement
}

Removemovieclip

This code deletes the movie clip (MC) that was created with the Attachmovie or Duplicatemovieclip method of the MovieClip object or created with a duplicatemovieclip action

Plainly Duplicatemovieclip's relationship with Removemovieclip is like Loadmoive and unloadmoive.

Format:

Removemovieclip (target);

The "target" here is the name of the MC created with Duplicatemovieclip.

Because I have not been successful, the following source file is the holy fish to help me do, thank him for this

Appendix: SINKS JINSHUAI. FLA

StartDrag

This code is used to drag the movie clip (MC)

Format:

StartDrag (target, [lock center Point, left, top, right, bottom]);

This code is very simple, please look at the source file below

Annex: Startdrag.rar

Some people have asked such a question how to put the button hand-type did not, okay, today I will give you a piece of good?

Usehandcursor This property is to change the hand shape of the mouse

Its value is a logical value one is true and one is False

Here is an example
by tongxiao198546

Appendix: Gang Wang tuo -2.fla

Stopdrag

Yesterday we learned Stardrag, today will learn Stopdrag, the two code is a pair, Stopdrag is the release of the current mouse drag object. This is very simple, the following is the source file you should be able to understand all, the two code after learning that everyone should be able to do a simple puzzle game

Annex: Stopdrag.rar

  updateafterevent (thank Bluepoint and holy Fish for help)

Updateafterevent (clipevent)

Can only be used in the action of the film clips, so that a processing of the Clipevent event to refresh the movie display. Although mouse and movie fragment events are performed when an event occurs, the event may have been executed several times, due to the limit of the movie fps (the number of frames displayed per second), only if the changes were made when the event was played to the next frame. In order for the event to function in real time, updateafterevent can be invoked in event handling to make the animation appear smooth

This is the source file, as in the box, put the updateafterevent (), remove the comparison, very obvious

Appendix: Gang Wang tuo -8.fla

Delete

Today we are officially entering variable learning!!!!

Today to learn the code is delete, this word we should all know, yes, is to delete the meaning of the code in the variable appears in it everyone can guess what use it, that is to delete the variable!!! (Xi Hee, just start learning variables first to learn is to delete variables)

Don't say anything else, look at the source file.

Note: The source file defines the variable as Var, and also the code to be learned in the variable

The purpose of this source file is when the mouse is pressed when the dynamic text box above the value of the variable assigned to it (the text box in the point, then look at the property panel, in the lower right there is a variable text box, where the text box refers to the name of the variable)

Annex: Delete.rar

Var

This code is the function of defining variables

Format:

var variable 1 [= value]

A simple equation is this: var variable = value of variable

The source file is also in the code above

With

The purpose of this code is to specify an object and use statement parameters to evaluate expressions and actions in the object.

Format:

With (object) {
Statement
}

The purpose of the following source file is to set the X and Y positions of the movie clips in the scene, where _x and _y are written in expert mode

Annex: With.fla

Break

This code is used in both the loop body and the Switch......case statement, and its function is to exit the other parts of the loop body

Flashboy82:

Let me add a couple of words,

For example, the use of break,,,, the following code can not be used for the true purpose of the learner's reference only

if (i<=10) Then{gotoandplay (20)}
Else{break};

Note If the variable i is less than or equal to 10 then skip to the 20th Stitch to run the program ... Otherwise jump out of the program.

Switch......case......default

This is three code, and you can find the format in the condition/loop:

switch (expression) {
case conditions;
Statement

statement;]
}

What they mean is that if the result of the expression after the switch equals the condition following the case, then execute the statement under this case, and if the default is added, then the statement under default will be executed without a combination of the preceding one.

The following are the source files

It means that if the CC1 is 1, then the CC displays "Blue teapot", and if it's 2, it shows "green tea."

Annex: Switch.fla

Continue

When the default is over, change the continue.

Look at the teapot busy

Brother, help me!

Tutorial will not be written directly on the source file bar. Oh!

By Lone Star, the Shadow of Loneliness

This is an attachment (source file)

Annex: Continue.fla

Do......while

Because the machine has ready-made source files, directly from the bar, tutorials-also annoying you old flash to add it. Hey! ~

Annex: Dowhile.fla

while

The function of this code is the loop, each time the loop processing, will first see whether to meet the conditions, if satisfied on the execution of the following statement, if not satisfied to jump out of the loop.

Format:

while (condition) {
Statement
}

The following source files are added from 1 to 100 effect

Annex: While.fla

Else

The function of this statement is to judge,,,,

Example

if (password==passwrod1) {gotoAndPlay (2)} else{gotoandplay (3)}

by flashboy82

ElseIf

And if it works together, it's also a judgment.

Example

if (password==password1) {gotoAndPlay (2)}    ElseIf (passwrod!=password1) {gotoAndPlay (3)}

Program Description:

If two passwords equal jumps to the second stitch to execute,, otherwise if two passwords are not equal to skip to the third stitch ...

Generally such sentences are used in the flash with the background to do landing page,,,

by flashboy82

If......elseif ...

That is, if the first condition is to be made after the first if statement, if the second condition is paid, execute the statement below ElseIf, so that the nth condition

for

This is also a circular statement

Format:

for (initial value; conditional expression; variable update expression) {statement;
}

Initial values: Set the initial value of a variable, used to loop, in the source file can be seen.

Conditional expression: When the initial value of the variable to pay the condition to continue to cycle, otherwise jump out of the loop.

Variable update expression: When the variable of the initial value is changed according to a certain rule.

The following source files are added to the effect from 1 to 100

Note : One of the i++ means i=i+1, which seems to have this in the source file above, as explained here.

Annex: For.fla

For......in

In Flash help.

Example

The following example uses the for.. In iteration the properties of an object:

MyObject = {name: ' Tara ', age:27, City: ' San Francisco '}; for (name in MyObject) {  trace ("myObject." + name + "=" + Myobject[name]);}

The output of this example looks like this:

Myobject.name = Tara
Myobject.age = 27
myobject.city = San Francisco

The following example adds the TypeOf operator to the. In together to iterate a particular type of child:

for (name in Mymovieclip) {  if (typeof (Mymovieclip[name]) = "MovieClip") {   trace ("I have a movie clip child name D "+ name);  }}

The following example enumerates the children of a movie clip and sends each child to the second frame of its respective timeline. The Radiobuttongroup movie clip is a parent that has more than one child: _redradiobutton_, _greenradiobutton_, and _blueradiobutton.

for (var name in Radiobuttongroup) {radiobuttongroup[name].gotoandstop (2);}

By the Holy Fish

The first example I understand is this:

The statements inside the brackets were executed 3 times, each time before the name was assigned to "name", "Age", "City";

You can add one more line:

Trace ("Name=" +name);
You can see that name is at the last value "City", so that the parameter in front is a string property

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.