Actionscript 3 - First Steps XI__actionscript

來源:互聯網
上載者:User
Actionscript 2 wasn't that bad after all, but a few things drove some developers crazy. For example if you initialized a member variable with an Object, this member magically behaved like a static classmember, due to the storage of the member in the prototype. In ActionScript 3 this works just like expected, as you can see here.
//////////
在AS2中的老問題,在AS3中得到解決了。以內聯方式初始化數組和對象,屬性可能變成靜態成員。(可以參看LUAR的書《ACTIONSCRIPT 2.0與RIA應用程式開發》80頁)

在AS2裡面
Test1.as
import Test2;
class Test1 extends MovieClip
{
    public function Test1 ()
    {
        var t1:Test2 = new Test2 ();
        var t2:Test2 = new Test2 ();
    }
}

Test2.as
class Test2
{
    private var a:Array = new Array ();
    function Test2 ()
    {
        a.push (a.length);
        trace (a);
    }
}

數組變成靜態成員,與預想的結果不一致
輸出
0
0,1

在AS3中

package {
    
    import flash.util.trace;
    import flash.display.MovieClip;

    public class Test1 extends MovieClip {
        
        public function Test1() {
            var t1:Test2 = new Test2();
            var t2:Test2 = new Test2();
        }
        
    }
    
    private class Test2 {
        
        private var a:Array = new Array();
        
        public function Test2() {
            a.push( a.length);
            trace(a);    
        }
        
    }
    
}

輸出正常的結果
0
0

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.