Report abuse

NativeWindowDecorator.as

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package {
	import flash.desktop.NativeApplication;
	import flash.display.NativeWindow;
	import flash.display.NativeWindowInitOptions;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	
	
	public class NativeWindowDecorator {
		
		private var _target:Sprite;
		
		public function get target():Sprite {
			return _target;
		}
		
		public function set target(value:Sprite):void {
			if(value != _target) {
				_target = value;
				addWindowDecorations();
			}
		}
		
		public function NativeWindowDecorator(target:Sprite) {
			_target = target;
			addWindowDecorations();
		}
		
		public function addWindowDecorations():void {
			if(_target == null)	
				return;
			else {
				var win:NativeWindow = new NativeWindow(
					new NativeWindowInitOptions());
				win.activate();
				win.addEventListener(Event.CLOSE, 
					function(e:Event = null):void {
						NativeApplication.nativeApplication.exit(0);
					});
				
				win.stage.addChild(_target);

				_target.stage.align = StageAlign.TOP_LEFT;
				_target.stage.scaleMode = StageScaleMode.NO_SCALE;
				
				win.width = _target.width;
				win.height = _target.height;
				
			}
		}

	}
}

DecoratorTest.as

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package {
	
	import flash.display.Sprite;

	public class DecoratorTest extends Sprite {
		
		public function DecoratorTest() {
			graphics.clear();
			graphics.beginFill(0xcbd4dd);
			graphics.drawRect(0, 0, 200, 200);
			graphics.endFill();
			
			var d:NativeWindowDecorator = new NativeWindowDecorator(this);
		}
		
	}
}