English 中文(简体)
Flex3:如何“重新加载”组件
原标题:Flex3: How to "Re-load" A Component

实际上,我如何“重置”一个组件,使其看起来像第一次加载时的样子。例如,我在一个HBox中有3个按钮。它们以红色开头,可见,并带有标签。然后,我以编程的方式对它们进行不同的更改——更改其中一些的颜色,更改一些的可见性,等等。

然后我需要“重新加载”这个HBox,让它恢复到一开始的样子。有简单的方法吗?(我有很多组件需要更改)。

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

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

    <mx:Button id="button3" 
        label="button1" 
        fillColors="[red, red]"  
        toggle="true" click="myClickHandler"/>
</mx:HBox>

如果你有什么建议,请告诉我。非常感谢。

-拉克西米

最佳回答

您在运行时更改此代码时已经遇到问题。只需编写一个方法将其更改回默认状态即可。那可能就是我要做的。

或者,如果这是一个封装的组件,您可以始终使用removeChild删除它,创建另一个实例,并将新实例放在同一个位置。


根据注释,以下是一些用于在组件的子级上循环并更改属性的psuedo代码:

for (var i : int =0; i<hBox.numChildren; i++){
  var child : UIComponent = hBox.getChildAt(i);
  child.setStyle( style , defaultValue );
  child.property =  default value 
}
问题回答
<mx:Application>
    <mx:Script>
        private function onColorChange():void
                {
                    can.removeAllChildren();

                    var loader:Loader = new Loader();
                    loader.load(new URLRequest( assets/images/logo/1.png ));
                    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);

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

                    //can.addChild(image);

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

                    can.addChild(txt);

                    can.mask = txt;
                    //applyFilter(CC.uint2rgb(cp.selectedColor));
                }

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

                    can.graphics.clear();   
                    can.graphics.beginBitmapFill(event.currentTarget.content.bitmapData);
                    can.graphics.drawRect(rect.x,rect.y,rect.width,rect.height);
                    can.graphics.endFill();

                }
    </mx:Script>

    <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:Canvas>
        <mx:Style source="style.css"/>
    </mx:Application>

在本例中,我所做的是删除ma canvas(id=can)中的所有子项,然后进行n个更改,以退出组件,然后将thm添加回canvas,

这个程序是用多种方式屏蔽的,我的画布有两个孩子,我把ma文本作为掩码放在画布上,我用位图图像填充画布,就是这样

我跳到它hepls





相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Multiple Remote call made simultenously

I was making multiple remote calls and they are done sequentially and when I am getting a result event back it s triggering calls to all the methods with ResultEvent as an argument . I am supposed to ...

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Clearing RSL in Cache

I have built a flex application which has a "main" project and it is assosciated with a few RSL s which are loaded and cached once i run my "main" application. The problem i am facing is that the ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签