Learning Flash: depth understanding setInterval method
Related Tags:
We believe that the setInterval method certainly very familiar with, but many of their lack of in-depth understanding, as a result, there are more than a flash of time setInterval can be easily confused, the removal of partitions lID not removed, should not be removed when it cleared the. The Syntax for setInterval I do not repeat them, many articles have detailed below, to a few key setInterval.
1, and clearInterval setInterval are global function, that is _ global.setInterval (), and _ global.clearInterval ().
That we should all know, but may not have special attention. However, this point is very important we understand them. SetInterval the return value is an interval lID (digital), so this is the overall interval lID. For example, the following code:
Var rootID = setInterval (_root, "test", 500, "rootID");
Function test (arg) (
Trace (arg);
)
We use clearInterval (rootID) and the use of clearInterval (1) the role of the same.
2, and each time the call setInterval, will return a lID interval, the overall setInterval id value is the number of calls.
For example, the following code:
Var rootID = setInterval (_root, "test", 500, "rootID");
Btn1.onPress = function () (
SetInterval (_root, "test", 500, "btn1_ID");
)
Btn2.onPress = function () (
SetInterval (_root, "test", 500, "btn2_ID");
)
Function test (arg) (
Trace (arg);
)
In this example, we can use clearInterval (1) to remove the interval rootID. If we click btn1 click btn2, it can be used clearInterval (2) to remove the click btn1 ID generated by the interval, and with clearInterval (3) to remove the click btn2 ID generated by the interval. On the contrary, if we click btn2 and click on the first btn1, then clearInterval (2) is removed by the click btn2 interval ID.
3, adding to the interval lID identifier in the actual programming, with the above clearInterval (digital) can be this way is cleared interval ID, but once the ID excessive, we will be unable to identify the removal of any ID. Adding to the interval lID therefore it is very important identifier. But he must be assigned to an object's member variables.
For example, the following code:
Newtest ();
Function newtest () (
Var newID = setInterval (_root, "test", 500, "btn2_ID");
)
Function test (arg) (
Trace (arg);
)
This identification method is wrong, because testID is a local variable, the only role in the new method. Could not be used in other places clearInterval (newID) to remove this interval. Var removed and will be in front of the (at this time _ newID root is a member variable).
4, an additional clearance loadMovieNum loaded swf interval ID examples:
IntervalID2.swf in the document there is a partition ID:
Var IntervalID2 = setInterval (_root, "test", 1000, "IntervalID2");
Function test (arg) (
Trace (arg);
)
In IntervalID1.swf in:
LoadMovieNum ( "IntervalID2.swf", 1)
Btn1.onPress = function () (
ClearInterval (_level1.IntervalID2)
IntervalID1 = setInterval (_root, "test", 2000, "IntervalID1";
);
Btn2, onPress = function () (
ClearInterval (2) / / clearInterval (IntervalID1)
);
Function test (arg) (
Trace (arg);
)
In this case, if we click btn1 click btn2, then two partitions ID will be deleted, and if the click btn2, then IntervalID1 is not removed. Understand the above three points, which should be obvious that the.
Summary: Several key understand the above, I would like to use setInterval method Yiqingerbai will, and will not be afraid of the setInterval can clearInterval situation. If wrong, please correct me.
- Css learning Notes - yyy431706 (of Portland)
- Css learning pace
- CSS cascading style of learning [2]
- Css learning (1)
- CSS layout of the learning some ideas
- Css learning some experience
- Learning css 4
- CSS learning "text attributes"
- Learning css 3
- Five learning css
- CSS layout learning experience
- Css learning Notes (1)
- CSS cascading style of learning [1]
- CSS learning should pay attention to learning method
- Css learning Notes
- CSS learning
- Css learning in the Filter
- CSS learning from entry to the master
- Css learning my feelings!
- Learning CSS




