代码之家  ›  专栏  ›  技术社区  ›  Mac

flex编译器元数据“defaultproperty”

  •  1
  • Mac  · 技术社区  · 17 年前

    鉴于以下情况:

    <?xml version="1.0"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2009/mxml">
        <mx:Panel title="blah">
           <mx:Button />
        </mx:Panel>
    </mx:Application>
    

    你能告诉我在哪里吗 子元素 (例如mx:按钮)被分配到 父元素 (例如mx:panel)默认为mxmlc。你可以设置“ 默认属性 “编译器元数据标记,用于指定它们被分配到的位置,但当没有指定时,flex会做什么。

    例如,我已经遍历了所有flex类mx:panel继承自的源代码,但没有提到defaultproperty,这使我想知道defaultproperty的默认值是多少。

    对不起,我把文件都读了一遍。

    2 回复  |  直到 17 年前
        1
  •  4
  •   dirkgently    17 年前

    当以基于组件的方式编写时,默认属性允许您指定可以作为子标记使用的属性。如:

     <MyComp:TextAreaDefaultProp>Hello</MyComp:TextAreaDefaultProp>
    

    你也可以用:

     <MyComp:TextAreaDefaultProp defaultText="Hello" />
    

    如果你不具体说明会发生什么?你得不到那个属性的值。给定以下组件:

    package
    {
        // as/myComponents/TextAreaDefaultProp.as
        import mx.controls.TextArea;
    
        // Define the default property.
        [DefaultProperty("defaultText")]
    
        public class TextAreaDefaultProp extends TextArea {
    
            public function TextAreaDefaultProp() 
            {
                super();
            }       
    
            // Define a setter method to set the text property
            // to the value of the default property.
            public function set defaultText(value:String):void {
                if (value!=null)
                text=value;
            }
    
            public function get defaultText():String {
                return text;
            }
        }    
    
    }
    

    运行此代码段:

     <?xml version="1.0" encoding="utf-8"?>
     <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                layout="absolute" width="535" height="345"
                xmlns:local="*">
     <mx:VBox>
     <local:TextAreaDefaultProp id="a" defaultText="Hello"/>
     <local:TextAreaDefaultProp id="b" > World </local:TextAreaDefaultProp>
     <local:TextAreaDefaultProp id="c" />
     <mx:TextArea id="z"/>
     <mx:Button  click="{z.text = a.defaultText 
                                    + ' ' + b.defaultText
                                    + ' ' + (c.defaultText.length);}" />
    
    </mx:VBox>
    </mx:Application>
    
        2
  •  1
  •   Josh Tynjala Ivan Chernykh    17 年前

    编译器实际上将容器的子组件视为特殊情况。看看 childDescriptors 性质 mx.core.Container 为了一些解释。在mxml中创建flex组件实例时,它不会立即实例化。相反,将创建一个“描述符”,用于在将来某个时间实例化组件,具体由容器的 creationPolicy 财产。如果您添加 -keep-generated-actionscript 参数(或缩写, -keep )对于编译器参数,您将能够看到编译器从mxml生成的as3代码。

    推荐文章