0

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.

Somebody
  • 9,316
  • 26
  • 94
  • 142

2 Answers2

1

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

Ayoub Kaanich
  • 992
  • 8
  • 20
0

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);
    }
}
Scott
  • 948
  • 2
  • 13
  • 25
  • Thanks mate. An interesting idea. I have made a bit different. I have created an array with callbacks for each ui element and loop through it via single onResize event. – Somebody Mar 09 '13 at 10:40