Files
haxework/haxework/gui/Root.hx
2014-02-27 09:13:39 +04:00

44 lines
1.2 KiB
Haxe
Executable File

package haxework.gui;
import flash.Lib;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.DisplayObject;
import flash.events.Event;
import flash.display.Sprite;
class Root {
private var view:IView<Sprite>;
public function new(view:IView<Sprite>) {
this.view = view;
Lib.current.addChild(view.content);
var content:DisplayObject = view.content;
if (content.stage == null) {
content.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
} else {
onAddedToStage();
}
View.updater.update();
}
private function onAddedToStage(?_):Void {
var content:DisplayObject = view.content;
content.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
content.stage.scaleMode = StageScaleMode.NO_SCALE;
content.stage.align = StageAlign.TOP_LEFT;
View.updater.stage = content.stage;
content.stage.addEventListener(Event.RESIZE, onResize);
onResize();
}
private function onResize(?_):Void {
var content:DisplayObject = view.content;
view.width = content.stage.stageWidth;
view.height = content.stage.stageHeight;
//L.d("Screen", content.stage.stageWidth + "x" + content.stage.stageHeight);
}
}