44 lines
1.3 KiB
Haxe
Executable File
44 lines
1.3 KiB
Haxe
Executable File
package haxework.frame;
|
|
|
|
import flash.display.Sprite;
|
|
import haxework.gui.IView;
|
|
import haxework.gui.GroupView;
|
|
|
|
class FrameSwitcher extends GroupView implements IFrameSwitcher<Sprite> {
|
|
|
|
public var current(default, null):Null<IView<Dynamic>>;
|
|
private var frames:Map<String, IView<Dynamic>>;
|
|
|
|
public function new() {
|
|
super();
|
|
frames = new Map<String, IView<Dynamic>>();
|
|
current = null;
|
|
}
|
|
|
|
public function change(id:String):IView<Dynamic> {
|
|
if (current != null) {
|
|
if (current.id == id) return current;
|
|
var onHideethod:Dynamic = Reflect.field(current, "onHide");
|
|
if (onHideethod != null) Reflect.callMethod(current, onHideethod, []);
|
|
removeView(current);
|
|
}
|
|
current = frames.get(id);
|
|
addView(current);
|
|
if (content.stage != null) content.stage.focus = current.content;
|
|
var onShowMethod:Dynamic = Reflect.field(current, "onShow");
|
|
if (onShowMethod != null) Reflect.callMethod(current, onShowMethod, []);
|
|
return current;
|
|
}
|
|
|
|
override public function set_views(value:Array<IView<Dynamic>>):Array<IView<Dynamic>> {
|
|
views = [];
|
|
if (value.length > 0) {
|
|
for (view in value) {
|
|
view.pWidth = 100;
|
|
view.pHeight = 100;
|
|
frames.set(view.id, view);
|
|
}
|
|
}
|
|
return value;
|
|
}
|
|
} |