ActionScript use an array Summary

Related Tags:

  This paper extracts Since I recently produced AS2 grammar study for AS lovers exchange, learning. 

  Where more wrong or improper, please correct me, thank you. 

  Array: 
  AS2, there are two types of array of local cattle comparison: 
  1) Object array own any data type can be stored, instead of the C int a [2], [3] char a, someClass a [3]. 
  Of course, the downside is also immediately sudden out of no direct Create Object array. 
  2) fully dynamic arrays, the use of very simple, somewhat like Vector, but also more vulnerable to mistakes.    The dynamic here is that the size of an array boundary (of course, the dimension or to declare good). 

  Below are some on the array type personally think that the more important point in the summary, some of the often sprawling NEE are omitted, 
  Where or speak less about what's wrong so you must help me to point out that, we enhance common: 
  A 
  Following is a statement mistakes: 

  Var a [1]: Array = new Array (); 
  Function test (arr []: Array): Void 

  2 statement Mode 1 (Note here the use of all manner of the statement-type statement method) 

  Var a: Array = new Array (); 
  A [0] = 0; 
  A [1] = 1; 
  Trace (a); 
  / / Output 
0,1

  3 statement method 2 

  Var a: Array = new Array (4); 
  A [4] = 1; 
  Trace (a); 
  / / Output 
  Undefined, undefined, undefined, undefined, 1 

  Explained: dynamic arrays with a length [4] automatically after five. 

  4 statement Mode 3 
4.1

  Var b: Array = new Array (0,1,2,3); 
  Trace (b); 
0,1,2,3

  4.2 does not support this form of two-dimensional array of nested definition 

  Var b: Array = new Array ((1,2), (3,4), (5,6)); 
  Trace (b); 
  Trace (b [0] "," b [1] "" b [2] "" b [3]); 
  Trace (b [0] [0]); 
2,4,6
  2 4 6 undefined undefined 
  5 [] replaced by the C (); 

  Statement Mode 4 

  Var b: Array = [[1,2] [3,4] [5,6]]; 
  Trace (b); 
  Trace (b [0] "," b [1] "" b [2] "" b [3]); 
  Trace (b [0] [0]); 
1,2,3,4,5,6
  1,2 3,4 5,6 undefined / / b [0] with an array output trip. 
  A 

  6 2D dimension is the same dynamic settings: 

  Var b: Array = [[1,2] [3,4] [5,6]]; 
  B [2] [3] = 12; 
  Trace (b [2] [3]); 
  / / Output 
12

  7 other two-dimensional array statement: 
  7.1 through the first set corresponding parameters listed. 
  / / 

  2 * 3 Array Declare. 
  Var gRowIndex: Number = 2; 
  Var gColIndex: Number = 3; 
  Var a: Array = new Array (gRowIndex); 
  For (var i = 0; i <gRowIndex; i) 
  (A [i] = new Array (gColIndex); 
  For (var j = 0; j <gColIndex; j) 
  ( 
  A [i] [j] = String (i) String (j); 
  ) 
  ) 
  Trace (a); 
  / / Output 
00,01,02,10,11,12

  8 for an array of function parameters for the transfer. 
8.1

  Var b: Array = new Array (0,1,2,3); 
  Function test (arr: Array): Void 
  ( 
  Trace (arr [0] "," arr [1] "" arr [2] "" arr [3] ""); 
  ) 
  Test (b); 
  0 1 2 3 

8.2
  Two-dimensional array: 

  Var b: Array = [[1,2] [3,4] [5,6]]; 
  Function test (arr: Array): Void 
  ( 
  Trace (arr); 
  Trace (arr [0] "," arr [1] "" arr [2] "" arr [3] ""); 
  ) 
  Test (b); 
1,2,3,4,5,6
  1,2 3,4 5,6 undefined 

8.3
  The first transmission line parameters: 

  Var b: Array = [[1,2] [3,4] [5,6]]; 
  Function test (arr: Array): Void 
  ( 
  Trace (arr); 
  Trace (arr [0] "," arr [1] ""); 
  ) 
  Test (b [0]); 
  Test (b [1]); 
  Test (b [2]); 
1,2
  1 2 
3,4
  3 4 
5,6
  5 6 

  9 More: 
9.1

  Var gRowIndex: Number = 2; 
  Var gColIndex: Number = 3; 
  Var a: Array = [[0,1], [3,4,5 ]];// a certain Element of a vacant Position here [0] [2] 
  Trace (a); 
  For (var i = 0; i <gRowIndex; i) 
  ( 
  For (var j = 0; j <gColIndex; j) 
  ( 
  Trace (a [i] [j]); 
  ) 
  ) 
0,1,3,4,5
0
  A 
  Undefined 
3
4
5

  9.2 does not support dynamic dimension 

  Var b: Array = [5,6]; 
  B [0] [0] = 3; 
  Trace (b [0] [0]); 
  / / Output 
  Undefined. 

  9.3 an indirect object array to achieve example. 

  Var enArray = new Array (3); 
  / / ENEMY connected to the array ------ ----------- / / 
  For (var j = 0; j <3; j) ( 
  AttachMovie (the "baddie", "baddie" j, j 200); 
  EnArray _root [j] = [ "baddie" j]; 
  EnArray [j]. _x = 50 * j; 
  EnArray [j]. _y = 100; 
  ) 

9.4
  There are many practical examples are used, say, to preserve Color with array data, loading picture variable name, and so on. 


  10 deleted array elements: 
  10.1 One-dimensional: 

  Var p = new Array (1,2,3,4,5); 
  P.splice (1); 
  Trace (p); 
  Var t = new Array (1,2,3,4,5); 
  T.splice (2,1); 
  Trace (t); 
  / / Output 
  A 
1,2,4,5

  10.2 2D: 

  Var b: Array = [[1,2] [3,4] [5,6]]; 
  B [0]. Splice (0) / / delete c [0] [0] c [0] [1] 
  Trace (b); 
  Var c: Array = [[1,2] [3,4] [5,6]]; 
  C [1]. Splice (1); / / c [1] [1] 
  Trace (c); 
  , 3-6 
1,2,3,5,6

  11 length test: 

  Var b: Array = [1,2,2], [3,4], [5,6,4,5]]; 
  Trace (b.length); 
  Trace (b [0]. Length); 
  Trace (b [2]. Length); 
  / / Output 
3
3
4

  ================================================== ======= 
  After a month of added: 
  11 dynamic dimension: with JAVA in the same. 

  Var arr: Array = new Array (1); 
  Arr [0] = new Array (3); 
  Arr [0] [0] = 1; 
  Arr [0] [1] = 2; 
  Arr [0] [2] = 3; 
  Trace (arr); 
  Trace (arr [0] [0]); 
  Trace (arr [0] [1]); 
  Trace (arr [0] [2]); 
1,2,3
  A 
2

  12 new ways to load data (multiple attributes): 

  MData = new Array (); 
  MData.addItem ((label: "The ball momentum conservation (one-dimensional)," data: 0)); 
  MData.addItem ((label: the "three-momentum conservation (one-dimensional)," data: 1)); 
  MData.addItem ((label: "multi-plane collisions (2D)," data: 2)); 
  MData.addItem ((label: "mother balls" data: 3)); 

  V2Component for the ComboBox with the use of: 

  _root.menuCombo.dataProvider = MData; 

Related articles:

Bicolor interphase form (CSS version)
<html> <body> <style>   . DoubleColorTable tr (    Background-color: expression ( "# FFFFFF # EEEEEE." Split (",")[ rowIndex% 2])    )    </ Style>    <table Width="70%" border="1" ...
Reith Miao FLASH Guide Series - by less than button
  Miao think the animation is exquisite in its humor, and widely circulated, now think Miao launched a series of tutorial, with his customary humor vivid animation on the entry FLASH knowledge, Flash empire authorized reprint of the initial version of this article 11 lessons: by less than butto...
Analysis of site development at three stages
  With the following succinct description of the language Web site operators the core of the three stages, we leave you more thinking time!    Stage 1: Brand fired website    1.    The overall operation: Web site is all business in the early stages, started to b...
The trim achieve javascript
<script>   String.prototype.trim = function ()    (    / / Regular expression will be used before and after space    / / Alternative with an empty string.    Return this.replace (/ (^ \ s *) | (\ s * $) / g, "");    ) ...
Flash build QQ magic expression "prayer" super-detailed diagram
  In the new version of QQ chat window click "Choose Face" icon, you will see more expressions list "magic expression" tab.    This is new faces introduced QQ magic, its expression is different from the previous QQ, QQ magic expression more lively, vivid, it can j...