将效果宽度调整为百分比

时间:2015-07-20 10:44:14

标签: actionscript-3 flex actionscript effects

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

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

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

我试过跟随,但没有为我工作。

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

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

1 个答案:

答案 0 :(得分:1)

要将容器的大小调整为舞台宽度的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}"/> 

声明可绑定的var:

[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();
}

你决定选择哪种方式;)

希望能有所帮助。