2013-08-28 2 views
1

Canvas에서 다른 Canvas로 동적으로 추가 한 UIComponents를 복제 할 때 문제가 있습니다.Canvas에서 동적으로 추가 된 UIComponents를 복제하는 방법

이 예제를 따르지만이 시나리오에서는 childDescriptors가 null이되므로 동적으로 추가 된 구성 요소에는 작동하지 않습니다.

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal"> 
    <mx:Script> 
      <![CDATA[ 
       private function cloneButton_clickHandler (event:MouseEvent):void 
       { 
        var childDescriptors:Array = original.childDescriptors; 
        var descriptorsCount:int = childDescriptors.length; 
        for (var i:int; i < descriptorsCount; i++) 
        { 
         cloned.createComponentFromDescriptor(original.childDescriptors[i], 
                     false); 
        } 
        cloned.validateNow(); 
       } 
      ]]> 
    </mx:Script> 
    <mx:Button label="Clone Canvas" click="cloneButton_clickHandler(event);" /> 
    <mx:Canvas id="original" width="100" height="100" borderStyle="solid" > 
      <mx:Label text="Some Label" /> 
      <mx:ComboBox dataProvider="{['data1', 'data2']}" bottom="0" /> 
    </mx:Canvas> 
    <mx:Canvas id="cloned" width="100" height="100" borderStyle="solid" > 

    </mx:Canvas> 
</mx:Application> 

답변

-1

나는 childDescriptors와 객체를 복제 한 적이 있지만 기술자가 null로 설정, 또는 적어도 그 전에 설명을 복사하기 전에 복제를 수행하려고 할 수 있습니다.

설명자는 MXML 객체를 인스턴스화하는 과정의 일부로 null로 설정 될 가능성이 높습니다. 그렇게되기 전에 설명자를 얻을 수 있어야합니다.

자녀를 복제하려는 개체가 전달할 "initialize"또는 "preinitialize"이벤트를 사용해보십시오.

관련 문제