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. 

Related articles:

Sina search engine introduced
  Sina Net search engine is the global Chinese online resources enquiry system.    Provide websites, news, software, games and other inquiries.    Web site included abundant resources, and Categories norms and meticulous, following Chinese user habits.    At prese...
Ajax security - the problem should not be ignored
  XML security vendor Forum Systems last month in security issues, and on a warning, in his view, as more and more of the Ajax style of applications, many organizations need to consider potential security vulnerabilities and performance issues.    Forum Systems in Salt Lake City'...
JScript value in the type of sealing and uncrating
  JScript expando attributes of the object in the Object, Array type, such as increased use of an important means, but this means when the value types can not, for example,    Var str = "string1";    Str.method1 = function () (    / / Do something&nbs...
Rookie of acts with Dreamweaver MX 2004 (7) to open a browser window
  Original content of this site, please specify the source of reproduced I love DivCSS.    Open a browser window    The use of "open up the browser window" moves in a new window open designated URL.    You can specify the properties of the new window (...
CSS achieve dynamic display by the five-pointed star-level results
  Perhaps you see above this paragraph some Shengse, no, let us have a look at css code solution    <ul Class="star-rating">    <li Class="current-rating"> Currently 3.5 / 5 Stars. </ Li>    <li> <a Href="#&qu...