チェンジセット 415

差分発生行の前後
無視リスト:
コミット日時:
2008/05/18 00:48:12 (4 年前)
コミッタ:
yossy
ログメッセージ:

Updated Astro's Vector sample.

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/Astro/AstroVector/src/AstroVector.as

    r401 r415  
    1616                        addChild(_info); 
    1717                         
    18                         try { 
     18                        // Primitive Vector 
     19                        { 
     20                                var pv:Vector.<int> = new Vector.<int>(); 
     21                                 
     22                                pv.push(1); 
     23                                pv.push(2); 
     24                                pv.push(true); // is correct. 
     25                                pv.push(false); // Boolean will cast to int. 
     26                                pv.push('hoge'); // String too. 
     27                                 
     28                                trace(String(pv)); // 1,2,1,0,0 
     29                        } 
     30                         
     31                        // Custom Class Vector 
     32                        { 
    1933                                var a:* = new A(); 
    2034                                var b:* = new B(); 
    2135                                var c:* = new C(); 
     36                                 
    2237                                var v:Vector.<A> = new Vector.<A>(); 
     38                                 
     39                                v.push(a); 
     40                                v.push(b); 
     41                                 
    2342                                try { 
    24                                         trace('push<a>'); 
    25                                         v.push(a); 
    26                                         trace('push<b>'); 
    27                                         v.push(b); 
    28                                         trace('push<c>'); 
    29                                         v.push(c); 
     43                                        v.push(c); // is error. C can't cast to A. 
     44                                                   // but null is pushed instead. 
    3045                                } 
    3146                                catch (e:*) { 
    32                                         trace('e<' + e.toString() + '>'); 
     47                                        trace(e.toString()); // TypeError 
    3348                                } 
    34                                 trace('l<' + v.length + '>'); 
    35                                 for (var i:uint = 0; i < v.length; ++i) { 
    36                                         trace(String(v[i])); 
     49                                 
     50                                trace(String(v.length)); // 3. It isn't 2. 
     51                                trace(String(v)); // A, B, null 
     52                        } 
     53                         
     54                        // Cast 
     55                        { 
     56                                // Array to Vector 
     57                                var atv:Vector.<A> = Vector.<A>([new A(), new B()]); 
     58                                 
     59                                trace(String(atv.length)) // 2 
     60                                trace(String(atv)); // A, B 
     61                                 
     62                                // Vector to Array 
     63                                // is impossible...? 
     64                        } 
     65                         
     66                        // Length 
     67                        { 
     68                                var vl:Vector.<int> = new Vector.<int>(2); 
     69                                 
     70                                vl[0] = 1; // OK 
     71                                vl[1] = 2; // OK 
     72                                 
     73                                try { 
     74                                        vl[3] = 4; // Bad. Out of range. 
     75                                                   // Index must be (0 <= index <= length + 1). 
     76                                } 
     77                                catch (e2:*) { 
     78                                        trace(e2.toString()); // RangeError 
     79                                } 
     80                                 
     81                                vl[2] = 3; // OK 
     82                                vl[3] = 4; // OK. Because now length+1 is 3. 
     83                        } 
     84                         
     85                        // Fixed 
     86                        { 
     87                                var vf:Vector.<int> = new Vector.<int>(2); 
     88                                 
     89                                vf.fixed = true; 
     90                                 
     91                                vf[0] = 1; // OK 
     92                                vf[1] = 2; // OK 
     93                                 
     94                                try { 
     95                                        vf[2] = 3; // Bad. Length is fixed. 
     96                                } 
     97                                catch (e3:*) { 
     98                                        trace(e3.toString()); // RangeError 
     99                                } 
     100                                 
     101                                try { 
     102                                        vf.push(3); // Bad. Length is fixed. 
     103                                } 
     104                                catch (e4:*) { 
     105                                        trace(e4.toString()); // RangeError 
    37106                                } 
    38107                        } 
    39                         catch (ee:*) { 
    40                                 trace(ee.toString()); 
    41                         } 
    42                          
    43                         /* 
    44                          * output is: 
    45                          * 
    46                          * push<a> 
    47                          * push<b> 
    48                          * push<c> 
    49                          * e<TypeError: Error #1034> 
    50                          * l<3> 
    51                          * A 
    52                          * B 
    53                          * null 
    54                          */ 
    55108                } 
    56109