Flash as Learning: example Analysis this usage

Source: Internet
Author: User
Tags define contains
   refers to an object or movie clip instance.

1, In the on event handler function action attached to the button, this refers to the timeline that contains the button. Example 1-1: Put a button on the stage. Define a variable var i:number=0 on the timeline, and enter the following statement on the button
On (Press) {
The result of the trace (this)//output will be _level0, which means that this is the reference to the root timeline
Trace (THIS.I)//output will be 0
Instance 1-2: Put an MC on the stage. and enter the instance name MY_MC, put a button in the MC, define a variable var i:number=0 on the timeline, and enter the following statement on the button
On (Press) {
The result of the trace (this)//output will be _LEVEL0.MC, which means that this is a reference to the time axis of the MC object on the root timeline.
Trace (THIS.I)//output will be undefined because the time axis of the MC does not define I
In the on event handler function action attached to the button, this refers to the timeline that contains the button
2, In the on () onclipevent () event handle function action that is attached to the movie clip, this refers to the timeline of the movie clip itself.
Example 2-1: Put an MC on the stage and enter the instance name MY_MC, attaching the following actions to the MC:
On (Press) {
The trace (this)//output will be _LEVEL0.MC, stating that this is the MC itself, not the _level0 note the on () handle attached to the MC is different from the on () handle attached to the button
Instance 2-2: Put an MC on the stage and enter the instance name MY_MC to append the following actions to the MC:
Onclipevent (load) {
Trace (this)//output _LEVEL0.MC, stating that now this is the MC itself
}
Continue to enter the following statement
Onclipevent (enterframe) {
this._x+=2//now the MC to the right movement, what also? Because this is the MC itself
} 3, the button event is written on the hardwood. The thsi in {} points to the button itself
Instance 3-1 put a button on the stage and enter the instance Name button, and the following action is entered on the hardwood:
Button.onpress=function () {
Trace (this)//output is _level0.button, not _level0, which is written on the frame and written on the button is different
Instance 3-2 puts 10 buttons on the stage and enters the instance name Button0 .... 10, enter the following action on the frame: this["button" +i].onpress=function () {//The front of this refers to the root timeline _level0, this is because to reference button, this is necessary, and instance 3-1 can also be this.button.onpress=function (), but often we can omit it.
Trace (this)/is now click which MC, output which MC, because this is to point to this["button" +i]
} 4, The MC event is written on the hardwood. The same button event written on the hardwood is the same.
5, This in the defined function points to the timeline in which the function is located.
Instance 5-1 Enter the following action function on the hardwood go () {
var i=0
The trace (this)//output will be _level0, because the function go is in the timeline
Trace (THIS.I)//output will be undefined, because I is a local variable, only in this statement block is valid, you cannot access
}
Go () In addition: This can also be used to inform us of the road, such as using the ScrollPane component, using the component to display a picture, with the timeline to control the transparency of the picture, but do not know the image of the MC of the road, how to do? Now details the full process of the instance (for fear that someone is not aware of the usage of the component)
Steps:
1, import a picture to the library.
2, a new MC, the library of the diagram dragged into the MC. Figure:

   3, for the MC Plus connection, right click on the library of the MC, point connection, as shown in the diagram settings.

   4, back to the main scene, the library of the ScrollPane components dragged into the scene, and with the transformation tool to zoom in properly

   5, select the component, open the Properties panel, such as the figure input:

   6, now testing, in the assembly can display pictures. But did not control its transparency, resolved: Please double-click the MC in the library, enter trace (this) in the first frame of the time axis where the MC is located, and test the output _level0.path.spcontentholder

   7, in with the time axis input this.path.spcontentholder._alpha=50, see, you succeed!

Click here to download the source file



Related Article

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.