apache flex – Flex3: How to “Re-load” A Component – Education Career Blog

How do I, in effect, “reset” a component in order to have it look the the way it did when it first loaded. For example, I’ve got 3 buttons in an HBox. They start as red, visible, and have a label. I then programmatically make different changes to them– change the color of some of them, change the visibility of some of them, etc.

I then need to “reload” this HBox, have it revert back to the way it looked at the start. Is there an easy way to do this? (I have a lot of components that need to be changed).

    <mx:Button id="button1"
        fillColors="red, red" 
        toggle="true" click="myClickHandler"/>

    <mx:Button id="button2" 
        fillColors="red, red" 
        toggle="true" click="myClickHandler"/>

    <mx:Button id="button3" 
        fillColors="red, red"  
        toggle="true" click="myClickHandler"/>

If you have a suggestion, please let me know. Thank you.



You are already problematically changing this code at runtime. Just write a method to change it back to it’s default state. That is probably what I’d do.

Alternately, if this is an encapsulated component, you could always remove it with removeChild, create another instance, and put that new one in the same place.

Per comments, here is some psuedo code for looping over children of a component and changing properties:

for (var i : int =0; i<hBox.numChildren; i++){
  var child : UIComponent = hBox.getChildAt(i);
  child.property = 'default value'


        private function onColorChange():void

                    var loader:Loader = new Loader();
                    loader.load(new URLRequest('assets/images/logo/1.png'));

                    /* image= new Image();
                    image.source = "assets/images/logo/1.jpg";
                    image.setStyle('verticalCenter','0'); */


                    txt= new Text();
                    txt.text = "Ankur sharma";
                    txt.styleName = "font";
                    txt.setStyle('fontFamily','Anime Ace');
                    txt.rotation = -10;


                    can.mask = txt;

                private function onComplete(event:Event):void
                    rect = new Rectangle();
                    rect = txt.getBounds(can);  



    <mx:ColorPicker id="cp" change="onColorChange()"/>
        <mx:Canvas id="can" height="100%" horizontalCenter="0" verticalCenter="0" borderStyle="solid" borderColor="#CCCCCC" borderThickness="5">
            <mx:Image source="assets/images/logo/1.png" horizontalCenter="0" verticalCenter="0"/>
            <mx:Text text="Ankur Sharma" styleName="font" rotation="-10"/>
        <mx:Style source="style.css"/>

in this example, wht i m doin is i m removing all children in ma canvas(id=can) amd then then makeing n e changes, to exizting components and then adding thm back to the canvas,

this program is of masking n e ways, my canvas has two children, and i m putting ma text as a mask over the canvas, and i am filling the canva with bitmap image, thats it

i hop it hepls

Leave a Comment