Actionscript:DisplayObject相对宽度可能吗?

时间:2013-03-09 00:36:57

标签: actionscript-3 displayobject

是否有可能使任何子DisplayObject的宽度相对于HTML的父对象为100%?

例如,要在舞台调整大小时自动调整大小。

避免手动重绘所有ui。

2 个答案:

答案 0 :(得分:1)

如果您希望在整个舞台上完成此操作,请使用exactFit
stage.scaleMode=StageScaleMode.EXACT_FIT;
documentation here
或使用Flex

答案 1 :(得分:0)

我通常处理这个的方式是我有一个自定义类,它扩展Sprite,在舞台上监听Event.RESIZE,然后在每个类中覆盖该函数,因为通常我没有一个解决方案,我希望显示对象如何调整大小。您可以修改它以便为您的目的而工作。

public class ResizeableSprite extends Sprite {

    public function ResizeableSprite()
    {
        addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true);
        addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage, false, 0, true);
    }

    protected function onResize(eventObject:Event):void {
        // override
    }

    protected function onAddedToStage(eventObject:Event):void {
        root.stage.addEventListener(Event.RESIZE, onResize, false, 0, true);
    }

    protected function onRemovedFromStage(eventObject:Event):void {
        root.stage.removeEventListener(Event.RESIZE, onResize);
    }

    public function destroy():void {            
        removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
    }
}