Component clone

I am trying to duplicate a flex component at runtime.

For example, if I have this

mx: Button label = "btn" id = "btn" click = "handleClick (event)" / ">

i should be able to call the DuplicateComponent () function, and it should return the user interface component to me in the same way as above, including the listen button for events.

Can someone help me? thanks in advance

+1
source share
6 answers

Make a copy of the byte array. This code segment should do it for you:

// ActionScript file
import flash.utils.ByteArray;

private function clone(source:Object):*
{
    var myBA:ByteArray = new ByteArray();
    myBA.writeObject(source);
    myBA.position = 0;
    return(myBA.readObject());
}

One note, I myself did not write this code, I'm sure I got it from a message in the Flex Coder list.

+5

, actioncript .

, , VBox, "someVbox"

for (var i:uint = 0; i< 10; i++){
    var but:Button = new Button();
    but.label = 'some_id_'+i;
    but.id = 'some_id_'+i;
    but.addEventListener(MouseEvent.CLICK, 'handleClick');
    someVbox.addChild(but);
}

, 10 vbox .

+1

UIComponents . , , . , . , .

0

, : http://www.flexforum.org/viewtopic.php?f=4&t=1421

Google . , . ?

, . //etc... , .

ActionScript .

, , [ "styleName", "width", "height",...], :

var newUI:UIComponent = new UIComponent();
for each(var s:String in propArray) {
   newUI[s] = clonedUI[s];
}

( ), , .

0

mx.utils.ObjectUtil , , .clone(), , .

:

class MyClass implements ICanvasObject
{
    ...

    public function clone():ICanvasObject
    {
         var obj:MyClass = new MyClass(parameters...);
         return obj;
    }
}

, /.

0

, , , mx.utils.ObjectUtil.

from: http://livedocs.adobe.com/flex/201/langref/mx/utils/ObjectUtil.html#copy()

copy()

copy (value: Object): Object . . , .

, . UIComponent, TextInput. UIComponent, clone() .

: Object - , .

-

0

Source: https://habr.com/ru/post/1779012/