以百分比调整效果宽度

Resize effect widthto in percentage

我在一个主容器中有两个容器。
一个容器有 20% 的宽度,另一个容器有 80% 的宽度。
现在我想在按钮点击时隐藏 20% 的容器,所以我使用。

<s:Resize id="resizeHide" widthTo="0" target="{fstContainer}"/>

现在,在同一个按钮上单击我想将该容器的大小调整 20% 那么解决方案是什么。

我试过跟随但对我不起作用。

<s:Resize id="resizeShow"  widthTo="20" target="{fstContainer}"/>

我无法设置固定宽度。调整大小效果只会占用像素宽度。

要将容器的大小调整为舞台宽度的 20%,您只需这样做:

您的 Resize 效果:

<s:Resize id="resizeShow" target="{fstContainer}"/>

然后是你的按钮:

<s:Button id="btn_resize" label="Resize" click="resizeShow.widthTo = stage.stageWidth / 5; resizeShow.play();"/>

编辑:

第二种方式,是使用数据绑定,像这样:

<s:Resize id="resizeShow" widthTo="{_20_percent}" target="{fstContainer}"/> 

声明可绑定变量:

[Bindable] protected var _20_percent:Number;

然后,您可以在您的应用程序创建完成时或将其添加到舞台时设置它的值,...:

protected function on_addedToStage(event:Event):void
{
    _20_percent = stage.stageWidth / 5;
}

protected function on_creationComplete(event:FlexEvent):void
{
    // here of course, as you know, the stage is not yet accessible
    _20_percent = FlexGlobals.topLevelApplication.width / 5;
}

当然,这里你只需要使用一个事件处理程序来设置值。

第三种方式,是在用户单击调整大小按钮时动态创建 Resize 效果:

protected function btn_resize_onClick(event:MouseEvent):void
{
    var resizeShow1:Resize = new Resize();
        resizeShow1.target = fstContainer;
        resizeShow1.widthTo = stage.stageWidth / 5;
        resizeShow1.play();
}

并且由您来决定您喜欢哪种方式 ;)

希望对您有所帮助。