2011-03-24 50 views

回答

1

你沒有一個相當於名單()在AS3。 0並且執行一個真的很難(幾乎不可能)。

原始類型:Boolean,int,Number,String和uint不能(手動)通過引用傳遞並通過此引用進行更改。這是因爲Flash在內部將它們存儲爲不可變對象。所以當它通過值傳遞時,它實際上是通過引用傳遞的,但數據不能被改變(見鏈接2)。

例子:

var obj:Object = {xy:21,yx:24}; 
    var num:Number = 24; 
    public function Sample():void{ 

     trace(obj.xy,obj.yx,obj.hey); 
     boom(obj); 
     trace(obj.xy,obj.yx,obj.hey); 
     heya(obj); 
     trace(obj.xy,obj.yx,obj.hey); 
     nullify(obj) 
     trace(obj.xy,obj.yx,obj.hey); 
     trace("Testing number"); 
     trace(num); 
     numer(num); 
     trace(num); 

    } 

    function boom(obj1:Object){ 
     var i:uint=0; 
     obj1.xy=34; 
     obj1.yx=34; 

    } 

    function heya(obj2:Object){ 

     obj2.hey = "hehe"; 
    } 

    function nullify(obj3:Object){ 

     obj3=null; 
    } 

    function numer(xz:Number){ 
     xz=45; 
    } 
時功能樣品()運行時,我們得到以下輸出

21 24 undefined 
34 34 undefined 
34 34 hehe 
34 34 hehe 
Testing number 
24 
24 

因此,我們可以得出結論,我們可以通過修改一個對象的屬性(它們添加或更改他們),但我們不能改變對象本身。我們也不能改變一個原始類型變量的值。

功能參數: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f56.html

數據類型: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f9c.html