Flash:with statement points to its own small way

Source: Internet
Author: User
Statement en, for with, I do not know what you flasher is a kind of understanding. In fact, with is theoretically not a very important statement, without with, many functions can still be implemented, because with itself is not responsible for creating, recycling any SWF resources.

However, the presence of with has greatly facilitated the design of our designers. The with in the code allows us to more clearly manage the specific MC.

For example, in a complex logic control to operate on the MC1,MC2,MC3, with a can make the program structure clearer.

With (MC1) {
//....
}
With (MC2) {
//...
}
With (MC3) {
//...
}

And the combination of the with and the method that can return the MC instance simplifies the program, for example

With (Mc0.duplicatemovieclip ("aw", 1)) {
Set the Properties for the Mc-aw
}

However, there is a problem that has been plagued by numerous flasher including mine. That's where this is pointing in with.

In with, you can access the properties of the MC by using _x,_y,_width, but this cannot point to yourself. This is related to the kernel of the WITH statement itself. I used to be depressed for a long time, for example, I want to add a variable to this MC, but can not use This.myvar = xxx; in fact, we do not care about these, because the MC itself according to the properties to find themselves, it is not impossible. Here are two attributes that are easily overlooked: _parent, _name.

Just need to set a handle to point to yourself on it, and we can set it to

Getthis = _parent[_name];

In this way, getthis is equivalent to this. More operations on the MC can be done with getthis, such as adding variables that can be used

GETTHIS.T = 19;

and the direct writing "t=19" is actually to assign this value to the parent of the MC.

Interestingly, using the with and then getthis nesting can still get itself, so that you can write an infinite hierarchy of nesting. Of course, this is only to illustrate the role of getthis, there is no meaning.



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.