2009-03-30 3 views
1

는 주어진 다음의 :Flex 컴파일러 메타 데이터 "DefaultProperty"

<?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 :. 패널) 기본적으로 mxmlc. "DefaultProperty"컴파일러 메타 데이터 태그를 지정하여 할당 된 위치를 지정하지만 지정되지 않은 경우 flex가 수행하는 작업을 지정할 수 있습니다.

예를 들어, mx : Panel이 상속 한 모든 flex 클래스의 소스를 살펴보고 DefaultProperty가 언급되지 않았기 때문에 DefaultProperty의 기본값이 궁금합니다.

불편을 끼쳐 드려 죄송하지만 문서를 자세히 읽었습니다.

답변

4

AS 기반 구성 요소를 작성할 때 기본 등록 정보를 사용하면 하위 태그로 사용할 수있는 등록 정보를 지정할 수 있습니다. 예 :

당신은뿐만 아니라 사용할 수도
<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> 
1

컴파일러는 실제로 특별한 경우로 컨테이너의 하위 구성 요소를 처리합니다. 몇 가지 설명을 위해 mx.core.Container이라는 childDescriptors 속성을 살펴보십시오. MXML로 Flex 구성 요소 인스턴스를 만들면 즉시 인스턴스화되지 않습니다. 대신 "설명자"가 만들어지고 컨테이너의 creationPolicy 속성에 의해 결정된대로 나중에 구성 요소를 인스턴스화하는 데 사용됩니다. -keep-generated-actionscript 인수 (또는 축약 된 버전 -keep)를 컴파일러 인수에 추가하면 컴파일러에서 MXML에서 생성하는 AS3 코드를 볼 수 있습니다.