/src/net/peteshand/asWindow/Window.as

https://bitbucket.org/nidinthb/as3-window
ActionScript | 307 lines | 184 code | 30 blank | 93 comment | 12 complexity | e1708510f1401f6e73701c85c0a8c5de MD5 | raw file
  1. package net.peteshand.asWindow
  2. {
  3. import flash.display.Sprite;
  4. import flash.events.Event;
  5. import flash.events.EventDispatcher;
  6. import net.peteshand.asWindow.events.WindowEvent;
  7. import net.peteshand.asWindow.javascript.JsInterface;
  8. /**
  9. * ...
  10. * @author Pete Shand
  11. */
  12. public class Window extends EventDispatcher
  13. {
  14. private var _index:int;
  15. private var sprite:Sprite = new Sprite();
  16. public function Window()
  17. {
  18. JsInterface.init();
  19. _index = JsInterface.newWindow();
  20. JsInterface.addEventListener(WindowEvent.PROMPT_ANSWERED, OnPromptAnswered);
  21. JsInterface.addEventListener(WindowEvent.CONFIRM_ANSWERED, OnConfirmAnswered);
  22. JsInterface.addEventListener(WindowEvent.OPEN, OnOpen);
  23. JsInterface.addEventListener(WindowEvent.CLOSE, OnClose);
  24. JsInterface.addEventListener(WindowEvent.MOVE, OnMove);
  25. JsInterface.addEventListener(WindowEvent.RESIZE, OnResize);
  26. }
  27. private function OnOpen(e:WindowEvent):void
  28. {
  29. if (e.index == index) {
  30. dispatchEvent(new WindowEvent(WindowEvent.OPEN));
  31. }
  32. }
  33. private function OnClose(e:WindowEvent):void
  34. {
  35. if (e.index == index) {
  36. dispatchEvent(new WindowEvent(WindowEvent.CLOSE));
  37. }
  38. }
  39. private function OnMove(e:WindowEvent):void
  40. {
  41. if (e.index == index) {
  42. var windowEvent:WindowEvent = new WindowEvent(WindowEvent.MOVE);
  43. dispatchEvent(windowEvent);
  44. }
  45. }
  46. private function OnResize(e:WindowEvent):void
  47. {
  48. if (e.index == index) {
  49. var windowEvent:WindowEvent = new WindowEvent(WindowEvent.RESIZE);
  50. dispatchEvent(windowEvent);
  51. }
  52. }
  53. public function open(url:String):void
  54. {
  55. JsInterface.openWindow(index, url);
  56. }
  57. public function runScript(script:String):void
  58. {
  59. trace("runScript");
  60. JsInterface.runScript(index, script);
  61. trace("runScript2");
  62. }
  63. public function close():void
  64. {
  65. JsInterface.close(index);
  66. }
  67. public function get state():String
  68. {
  69. return JsInterface.getState(index);
  70. }
  71. public function alert(msg:String):void
  72. {
  73. JsInterface.alert(index, msg);
  74. }
  75. public function consoleLog(msg:String):void
  76. {
  77. JsInterface.consoleLog(index, msg);
  78. }
  79. public function print():void
  80. {
  81. JsInterface.print(index);
  82. }
  83. public function prompt(msg:String, defaultText:String):void
  84. {
  85. JsInterface.prompt(index, msg, defaultText);
  86. }
  87. private function OnPromptAnswered(e:WindowEvent):void
  88. {
  89. if (e.index == index) {
  90. var windowEvent:WindowEvent = new WindowEvent(WindowEvent.PROMPT_ANSWERED);
  91. windowEvent.value = e.value;
  92. dispatchEvent(windowEvent);
  93. }
  94. }
  95. public function confirm(message:String):void
  96. {
  97. JsInterface.confirm(index, message);
  98. }
  99. private function OnConfirmAnswered(e:WindowEvent):void
  100. {
  101. if (e.index == index) {
  102. var windowEvent:WindowEvent = new WindowEvent(WindowEvent.CONFIRM_ANSWERED);
  103. windowEvent.value = e.value;
  104. dispatchEvent(windowEvent);
  105. }
  106. }
  107. public function focus():void
  108. {
  109. JsInterface.focus(index);
  110. }
  111. public function blur():void
  112. {
  113. JsInterface.blur(index);
  114. }
  115. public function get index():int
  116. {
  117. return _index;
  118. }
  119. public function get height():int
  120. {
  121. return JsInterface.getHeight(index);
  122. }
  123. public function set height(value:int):void
  124. {
  125. JsInterface.setHeight(index, value);
  126. }
  127. public function get width():int
  128. {
  129. return JsInterface.getWidth(index);
  130. }
  131. public function set width(value:int):void
  132. {
  133. JsInterface.setWidth(index, value);
  134. }
  135. public function get x():int
  136. {
  137. return JsInterface.getX(index);
  138. }
  139. public function set x(value:int):void
  140. {
  141. JsInterface.setX(index, value);
  142. }
  143. public function get y():int
  144. {
  145. return JsInterface.getY(index);
  146. }
  147. public function set y(value:int):void
  148. {
  149. JsInterface.setY(index, value);
  150. }
  151. public function get align():String
  152. {
  153. return JsInterface.getAlign(index);
  154. }
  155. public function set align(value:String):void
  156. {
  157. JsInterface.setAlign(index, value);
  158. }
  159. public function get callback():Function
  160. {
  161. return JsInterface.getCallback(index);
  162. }
  163. public function set callback(value:Function):void
  164. {
  165. JsInterface.setCallback(index, value);
  166. }
  167. public function get url():String
  168. {
  169. return JsInterface.getURL(index);
  170. }
  171. public function set url(value:String):void
  172. {
  173. JsInterface.setURL(index, value);
  174. }
  175. public function get useProxy():Boolean
  176. {
  177. return JsInterface.getUseProxy(index);
  178. }
  179. public function set useProxy(value:Boolean):void
  180. {
  181. JsInterface.setUseProxy(index, value);
  182. }
  183. public function inject(value:XML):void
  184. {
  185. JsInterface.inject(index, value);
  186. }
  187. /*public function get channelmode():Boolean
  188. {
  189. return JsInterface.getChannelmode(index);
  190. }
  191. public function set channelmode(value:Boolean):void
  192. {
  193. JsInterface.setChannelmode(index, value);
  194. }
  195. public function get directories():Boolean
  196. {
  197. return JsInterface.getDirectories(index);
  198. }
  199. public function set directories(value:Boolean):void
  200. {
  201. JsInterface.setDirectories(index, value);
  202. }
  203. public function get fullscreen():Boolean
  204. {
  205. return JsInterface.getFullscreen(index);
  206. }
  207. public function set fullscreen(value:Boolean):void
  208. {
  209. JsInterface.setFullscreen(index, value);
  210. }
  211. public function get location():Boolean
  212. {
  213. return JsInterface.getLocation(index);
  214. }
  215. public function set location(value:Boolean):void
  216. {
  217. JsInterface.setLocation(index, value);
  218. }
  219. public function get menubar():Boolean
  220. {
  221. return JsInterface.getMenubar(index);
  222. }
  223. public function set menubar(value:Boolean):void
  224. {
  225. JsInterface.setMenubar(index, value);
  226. }
  227. public function get resizable():Boolean
  228. {
  229. return JsInterface.getResizable(index);
  230. }
  231. public function set resizable(value:Boolean):void
  232. {
  233. JsInterface.setResizable(index, value);
  234. }
  235. public function get scrollbars():Boolean
  236. {
  237. return JsInterface.getScrollbars(index);
  238. }
  239. public function set scrollbars(value:Boolean):void
  240. {
  241. JsInterface.setScrollbars(index, value);
  242. }
  243. public function get titlebar():Boolean
  244. {
  245. return JsInterface.getTitlebar(index);
  246. }
  247. public function set titlebar(value:Boolean):void
  248. {
  249. JsInterface.setTitlebar(index, value);
  250. }
  251. public function get toolbar():Boolean
  252. {
  253. return JsInterface.getToolbar(index);
  254. }
  255. public function set toolbar(value:Boolean):void
  256. {
  257. JsInterface.setToolbar(index, value);
  258. }*/
  259. }
  260. }