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.