• 基础知识this[String]


    package
    {
        import flash.display.Sprite;
        public dynamic class StringTest extends Sprite
        {
            public 
    var testName:String;
            public 
    function StringTest(str:String)
            {
                testName
    =str;
            }
            public 
    function functionA():void
            {
                trace(
    "functionA is here!")
            }
            public 
    function functionB():void
            {
                trace(
    "functionB is here!")
            }
        }
    }
    this["rect"= new Rect();
    //rect.x = 450 //会提示错误,未定义的属性
    this.rect.x=this.rect.y=100//没问题
    this.rect.name="rect1";
    addChild(
    this["rect"]);

    this["rect"= new Rect();
    this.rect.x=this.rect.y=200;
    this.rect.name="rect2";
    addChild(
    this["rect"]);

    var rect:Rect=this.getChildByName("rect1") as Rect;
    trace(rect.x)


    var i:int=10;
    var j:int;
    while(j=i--)
    {
        trace(
    "i+j="+String(i+j))
    }

    var stringTest:StringTest=new StringTest("test_1");
    addChild(stringTest);
    stringTest[getFunctionName()]();
    trace(stringTest[
    "testName"]);
    stringTest[
    "rect"]=rect;
    stringTest.addChild(rect);
    function getFunctionName():String
    {
        
    var t:Number=getTimer();
        
    if(t%2==0)return "functionA";
        
    else return "functionB";
    }
    import flash.utils.Dictionary; 
             
    var a:Object = new Object(); 
             
    var b:Object = new Object(); 
             
    var dict:Dictionary = new Dictionary(); 
             dict[a] 
    = 1;                                   // dict[a] = 1; 
             dict[b] = 2;                                    // dict[b] = 2; 
             for (var prop:* in dict) { 
                  trace(prop);                              
    // traces: [object Object], [object Object] 
                  trace(dict[prop]);                      // traces: 1, 2 
             }

    注意:

     1、虽然在trace的时候,输出的还是[object Object],但是这个结果是对象的toString的结果。在Dictionary对象中,代表的是不同的对象引用。

     2、这里的prop的类型是*。这是很重要的,因为dict对象中的键可能是任何数据类型的。

    以下对Dictionary与Object的不同之处的一个小结:

    1、Object的键必须是字符串,或表示字符串的表达式(变量或函数),若不是字符串的表达式,则将调用toString()方法,将其转化为字符串;

    2、与Object不同的是,Dictionary使用的键是对象的引用,而不是字符串,且非原始对象键调用之前是通过全等运算符(===)来进行判断,并不会将数据类型强制转换之后再进行判断。

  • 相关阅读:
    蓝桥杯_基础训练_龟兔赛跑预测
    大数加法
    Splay!
    topsort
    各种方法
    有时候dfs可以简化各种组合的操作
    组合数学
    重新认识三观
    手速狗还是不行啊。。。
    set和map和pair 转自ACdreamers
  • 原文地址:https://www.cnblogs.com/ddw1997/p/2055483.html
Copyright © 2020-2023  润新知