Flash global variable lets you say goodbye to the tedious path

Source: Internet
Author: User
Tags array reference
Variables sometimes, there are some very important movieclip, such as some type of operation information of the MC (such as "a"), need to constantly change its properties, such as a text box. These changes are triggered by a number of different MC or button events, and even the button and MC that trigger these events are far away, and we need to turn a lot of detours to find this a. Then, you can save a in a global variable after a is established. Notice that we're just saving a pointer, not a MC instance. Then, after the other path to the operation of a, you can put the tedious _parent. All of this is removed. (Related articles:

Of course, it is unclear whether there is a difference in efficiency between the traditional method and the global variable reference method. I have done the following tests

_GLOBAL.R_HINT_MC = _root.createemptymovieclip ("A", 1);
Prefix r, representing reference, pointing meaning.
With (R_HINT_MC) {
Swapdepths (10);
}
With (a) {
Trace (Getdepth ());
Visible with method can successfully invoke the point of the global MC, the depth does change.
}
B.onrelease = function () {
Testa = Gettimer ();
Trace ("called");
for (var j = 1; j<100000; j + +) {
R_hint_mc.newarray = new Array ()
R_hint_mc.newarray[j]=r_hint_mc._currentframe
The result is about 2400-2500
No big change in MC
The result is about 2250 in a mcevent!!!
-----Local Looking
This._parent.a.newarray = new Array ();
THIS._PARENT.A.NEWARRAY[J] = R_hint_mc._currentframe;
The result is about 2200-2300
The result was about 2300-2500 in a MC!!!!
The result are about 2050 in a mcevent
}
Trace (Gettimer ()-testa);
};
/* Conclusion:
Global reference: • In the same time axis, less traditional reference
• Superior to traditional references in different time axes (on the time axis of the MC alone)
• In a MC event processing (not in the time axis of this MC), rather than the traditional reference
Personally feel that the third (i.e. event processing) in the more complex applications most frequently used, it also reflects the global variable some of the efficiency disadvantage, but compared to the program maintainability really improved.

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.