Research on data types and variables in Flash

Source: Internet
Author: User
Tags definition comments null null object object variables valid
Variables | data | data type

  Data types in Flash

1, the String value example: mytext= "F4", Mytex is a string, the string is a sequence composed of characters

2, numerical example mynum=2 mynum is the numerical value, may use the mathematical operation symbol to carry on the computation to them.


3, the logical value example Mypass=false Mypass is the logical value FALSE, the logical value is only two values, one is true, and the other is false.

4, Object object is a collection of attributes, each attribute has its own name and value, for example: a.b.c= "Ah", C is the value of the string "ah", C is the property of object B; B is the property of object A. Another example: Mc.play () MC is a movie clip object on the stage, MovieClip contains the method play can control the objects on the stage.

5. Movie clips are symbols that can play animation in Flash, which is the only data type that references graphic elements.

6, NULL null value is only one value null, it is a reference to a nonexistent value.

7, undefined value. Undefined values also have only one value undefined, which is a variable for which no value has been specified.

The above 7 types are simply introduced, do not want to say too much, want to really understand them, but also combine variables and other knowledge, carry out comprehensive learning, and can not learn them in isolation.

Second, the variable in Flash

A variable is actually an information container. The characteristics of the container are the same, but the contents can be different, for example: a bottle, can be filled with wine, water can also be loaded with kerosene. And the algebra of mathematics to understand: x=2, X can also equal to 3

There are three kinds of variables in Flash, local variable time axis variable global variable

To declare a variable to be simple, for example:

var I=1 so we're going to declare a local variable and we've already assigned a value.
I=1 so we're going to declare a timeline variable and we've already assigned a value.
_global.i=1 so we're going to declare a global variable and we've already assigned a value.

When declaring variables, there are several issues that we should be aware of:

1, the name of the variable is composed of letters or letters and arrays, can not be all composed of numbers, of course, can not be in the text; variable names can not be used in flash keyword and logical values, that is, such as play stop these display as dark blue words.

2. A local variable is a variable that is only valid in this block of statements; A time axis variable is a variable that can be accessed through a target path, and a global variable is a valid variable in the entire flash.

3, a lot of suggestions to use the var statement local variables, so that you can effectively control the conflict of variables, and strictly specify the data types of variables, when the input var i:, will automatically list the type let us choose.

Learn to use trace to track data. Now we use an example to illustrate the relevant variable data knowledge.

Example 1: Write the following as on the hardwood

On (Press) {//mouse click on button
Trace (myNum)//output variable, because there is no definition, so the first output is undefined
if (MyNum = = undefined) {//First click on this condition set up
MyNum = 1;//The command to execute this definition variable and assign a value
} else {
mynum++;//otherwise the variable itself +=1
}
}

Comments: After the first click of the button, because mynum is undefined, so the output mynum after the execution of mynum = 1; After the second click, because the variable has been declared, so the implementation of mynum++, Output 2, after the output 3, 4, 5 ...

Example 2: On the stage to create a MC, take the instance named MC, double-click this MC, in this MC Camphene into a MC, take the instance named MC1, select this MC1, open the Action panel, enter:

Onclipevent (load) {
var i:number=0
}

Then return to the scene, select the MC, open the Action panel input:

On (Press) {
Trace (i)
}

Click on the output is undefined, and then write again

On (Press) {
Trace (THIS.MC1.I)
}

Comment: Now output 0, what reason? Because I is defined in MC1, and the object currently clicked is MC,MC without the variable i, I in the MC1 of the MC, so it must be accessed through the path.

Example 3:

function Go () {
var i:number=0
}
Trace (i) function go () {
I=0
}
Trace (i)

Compare the results of the output to what is different.

Comments: The former output is undefined, because the local variable is only valid in this statement block, the latter is not a local variable, so the statement block is still valid.

Practice Recommendation: Download this FLA, only on the button to enter as, enter a single playback, enter a double stop. Hint: Use data undefined logical value, counter

Click here to download the source file



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.