我在将 Canvas 中动态添加的 UIComponents 克隆到另一个 Canvas 时遇到问题。
我遵循这个例子,但它不适用于动态添加的组件,因为在这个场景中 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>