Question

Is it possible to make for example 100% width to any child DisplayObject relatively to it's parent like in HTML?

To make auto-resize on stage resize for example.

To avoid redrawing all ui manually.

Was it helpful?

Solution 2

The way I usually handle this is I have a custom class that extends Sprite that listens for Event.RESIZE on the stage and then override that function in each class since usually I don't have a single solution for how I want display objects to act on resize. You could possibly modify this to work for your purposes.

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

OTHER TIPS

if you want this to be done on the entire stage use exactFit
stage.scaleMode=StageScaleMode.EXACT_FIT;
documentation here
or use Flex

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top