Skip navigation
Currently Being Moderated

How to clone a UIComponent ?

Jan 21, 2010 6:47 AM



Is there a solution to clone a UIComponent? There is a solution using ObjectUtil.copy method but it doesn't work for UIComponents. I have also tried using properties reflection, but it doesn't work either.


Thank you.


  • Currently Being Moderated
    Jan 21, 2010 1:39 PM   in reply to Sophie_cordier

    There is no way to clone.  You have to know which properties to copy to the

    new instance.

    Mark as:
  • Currently Being Moderated
    Jan 22, 2010 2:55 AM   in reply to Sophie_cordier

    You can use a try..catch statement to catch the error.



    Mark as:
  • Currently Being Moderated
    Calculating status...
    Jan 22, 2010 3:06 AM   in reply to Sophie_cordier

    This means that the activeEffects of UIComponent is only a getter with no associated setter, so you can not write in it, and your method can not work...

    As previous poster said, you can try to catch the errors to ignore such fields and see what happens once all the writable properties have been copied.


    Why exactly do you need to clone such a UIComponent?

    Mark as:
  • Currently Being Moderated
    Jan 25, 2010 11:35 AM   in reply to Flex harUI

    You can clone an Image like using the following, right?:


         import flash.display.Bitmap;
         import flash.display.BitmapData;
         import mx.controls.Image;
          * This class is used to clone an image for that it can be used
          * in multiple places simultaneously.
         public class ImageClonerUtil
              public static function cloneImage(image:Image):Image
                   var clone:BitmapData = Bitmap(image.source).bitmapData.clone();
                   var bitmap:Bitmap           = new Bitmap(clone);
                   var newImage:Image          = new Image();
                   newImage.source           = bitmap;
                   return newImage;
    Mark as:
  • Currently Being Moderated
    Jan 30, 2010 4:36 PM   in reply to Sophie_cordier

    Hi! I'm getting kinda late here but I'm still posting my workarround and see if it helps anyone, I managed to clone a component using the containers childDescriptors and createComponentFromDescriptor (click here to read a note on the functions - although is for flex 2, works in flex 3).


    This is a demo for the clonning in which all the children from a Canvas are cloned into another one....


    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="" layout="horizontal">
                   private function cloneButton_clickHandler (event:MouseEvent):void
                        var childDescriptors:Array = original.childDescriptors;
                        var descriptorsCount:int = childDescriptors.length;
                        for (var i:int; i < descriptorsCount; i++)
         <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 id="cloned" width="100" height="100" borderStyle="solid" >


    Hope This Helps!


    Mark as:
  • Currently Being Moderated
    Aug 23, 2013 3:38 AM   in reply to Gus187

    This way to make clone is better but I am facing an issue here, If we add UIComponents dynamically in "original" canvas instead of adding in tags , the "childDescriptors"  is null value and unable to make clone in this way.


    anyone having soluiton... please share with me.





    Mark as:
  • Currently Being Moderated
    Apr 10, 2014 12:23 AM   in reply to Sophie_cordier

    That's a good question, exactly the same as the one I have with the winforms UI component.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points