PageRenderTime 60ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/source/full/aw/external/JSInterface.as

http://jsinterface.googlecode.com/
ActionScript | 956 lines | 227 code | 66 blank | 663 comment | 29 complexity | 67ea15a254c5abe942464e06d2db50ed MD5 | raw file
  1. package aw.external{
  2. import aw.external.jsinterface.JSCore;
  3. import aw.external.jsinterface.JSInstanceCache;
  4. import aw.external.jsinterface.objects.JSDocument;
  5. import aw.external.jsinterface.objects.JSEvent;
  6. import aw.external.jsinterface.objects.JSHTMLElement;
  7. import aw.external.jsinterface.objects.JSNavigator;
  8. import aw.external.jsinterface.objects.JSObjectTypeMapper;
  9. import aw.external.jsinterface.objects.JSWindow;
  10. import aw.system.FlashPlayerType;
  11. import flash.display.DisplayObject;
  12. import flash.display.LoaderInfo;
  13. import flash.display.Stage;
  14. import flash.external.ExternalInterface;
  15. import flash.system.Capabilities;
  16. /**
  17. * It’s the main class of JSInterface library, it contains the most necessary methods for interaction with JavaScript environment.
  18. * This class contains “shortcut” methods for frequently used operations, such as page title changing, working with Cookie or loading
  19. * CSS and JavaScript files. Before starting working with the library make sure that it was initialized JSInterface.initialize()
  20. * method. Initialization is necessary to integrate the necessary JavaScript code to the HTML page for the JSInterface to be able
  21. * to operate correctly.
  22. * @example Example:
  23. <listing version="3.0">
  24. package {
  25. import aw.external.JSInterface;
  26. import aw.external.jsinterface.JSDynamic;
  27. import aw.external.jsinterface.objects.JSHTMLElement;
  28. import flash.display.Sprite;
  29. [SWF(width="20", height="20")]
  30. public class BodyOnClickExample extends Sprite{
  31. public function BodyOnClickExample():void{
  32. super();
  33. JSInterface.initialize(this);
  34. JSInterface.document.body.onclick = this.onclickHandler;
  35. var body:JSHTMLElement = JSDynamic.convert(JSInterface.document.body, JSHTMLElement);
  36. body.onclick();
  37. trace(JSInterface.document.links.length);
  38. }
  39. protected function onclickHandler():void{
  40. trace(' HTML Click! ');
  41. }
  42. }
  43. }
  44. </listing>
  45. * @public
  46. * @author Galaburda a_[w] Oleg http://www.actualwave.com
  47. */
  48. public class JSInterface extends Object{
  49. /**
  50. *
  51. *
  52. *
  53. * @private (constant)
  54. * @langversion ActionScript 3.0
  55. * @playerversion Flash 9.0.28.0
  56. */
  57. static private const GET_TITLE:String = 'JSIBrowser.getTitle';
  58. /**
  59. *
  60. *
  61. *
  62. * @private (constant)
  63. * @langversion ActionScript 3.0
  64. * @playerversion Flash 9.0.28.0
  65. */
  66. static private const SET_TITLE:String = 'JSIBrowser.setTitle';
  67. /**
  68. *
  69. *
  70. *
  71. * @private (constant)
  72. * @langversion ActionScript 3.0
  73. * @playerversion Flash 9.0.28.0
  74. */
  75. static private const GET_STATUS:String = 'JSIBrowser.getStatus';
  76. /**
  77. *
  78. *
  79. *
  80. * @private (constant)
  81. * @langversion ActionScript 3.0
  82. * @playerversion Flash 9.0.28.0
  83. */
  84. static private const SET_STATUS:String = 'JSIBrowser.setStatus';
  85. /**
  86. *
  87. *
  88. *
  89. * @private (constant)
  90. * @langversion ActionScript 3.0
  91. * @playerversion Flash 9.0.28.0
  92. */
  93. static private const GET_LOCATION:String = 'JSIBrowser.getLocation';
  94. /**
  95. *
  96. *
  97. *
  98. * @private (constant)
  99. * @langversion ActionScript 3.0
  100. * @playerversion Flash 9.0.28.0
  101. */
  102. static private const GET_TOP_LOCATION:String = 'JSIBrowser.getTopLocation';
  103. /**
  104. *
  105. *
  106. *
  107. * @private (constant)
  108. * @langversion ActionScript 3.0
  109. * @playerversion Flash 9.0.28.0
  110. */
  111. static private const GET_LOCATION_HASH:String = 'JSIBrowser.getLocationHash';
  112. /**
  113. *
  114. *
  115. *
  116. * @private (constant)
  117. * @langversion ActionScript 3.0
  118. * @playerversion Flash 9.0.28.0
  119. */
  120. static private const SET_LOCATION_HASH:String = 'JSIBrowser.setLocationHash';
  121. /**
  122. *
  123. *
  124. *
  125. * @private (constant)
  126. * @langversion ActionScript 3.0
  127. * @playerversion Flash 9.0.28.0
  128. */
  129. static private const GET_COOKIE_STRING:String = 'JSIBrowser.getCookieString';
  130. /**
  131. *
  132. *
  133. *
  134. * @private (constant)
  135. * @langversion ActionScript 3.0
  136. * @playerversion Flash 9.0.28.0
  137. */
  138. static private const SET_COOKIE_STRING:String = 'JSIBrowser.setCookieString';
  139. /**
  140. *
  141. *
  142. *
  143. * @private (constant)
  144. * @langversion ActionScript 3.0
  145. * @playerversion Flash 9.0.28.0
  146. */
  147. static private const GET_DEFAULT_STATUS:String = 'JSIBrowser.getDefaultStatus';
  148. /**
  149. *
  150. *
  151. *
  152. * @private (constant)
  153. * @langversion ActionScript 3.0
  154. * @playerversion Flash 9.0.28.0
  155. */
  156. static private const SET_DEFAULT_STATUS:String = 'JSIBrowser.setDefaultStatus';
  157. /**
  158. * Shows the necessity to duplicate JavaScript errors in Flash environment.
  159. * Such errors can occur upon wrongful acts (calling for a non-existing methods)
  160. * initiated by Flash Player environment.
  161. *
  162. *
  163. * @public
  164. * @langversion ActionScript 3.0
  165. * @playerversion Flash 9.0.28.0
  166. */
  167. static public var redirectJavaScriptExceptions:Boolean = true;
  168. /**
  169. * Instead of throwing error will show error description in OUTPUT window, using trace() command.
  170. *
  171. *
  172. * @public
  173. * @langversion ActionScript 3.0
  174. * @playerversion Flash 9.0.28.0
  175. */
  176. static public var traceExceptionOnly:Boolean = true;
  177. /**
  178. * The function that processes errors that occurred beyond the request from Flash Player.
  179. * Such errors can occur during execution of JavaScript functions called from Flash Player
  180. * by time-out (for example, using JSInterface.callLater() method).
  181. *
  182. *
  183. * @public
  184. * @langversion ActionScript 3.0
  185. * @playerversion Flash 9.0.28.0
  186. */
  187. static public var exceptionHandler:Function;
  188. /**
  189. * The function that processes errors that occurred beyond the request from Flash Player.
  190. * Such errors can occur during execution of JavaScript functions called from Flash Player
  191. * by time-out (for example, using JSInterface.callLater() method).
  192. *
  193. * @public
  194. * @langversion ActionScript 3.0
  195. * @playerversion Flash 9.0.28.0
  196. */
  197. static public var allowJavaScriptAccess:Boolean = false;
  198. /**
  199. * It allows access to Flash Player objects from JavaScript environment.
  200. * If you set it as TRUE, you get a possibility to create and call for
  201. * objects located in the Flash Player environment. If the value is FALSE,
  202. * then the access to objects from Flash Player environment is limited to
  203. * objects transferred to JavaScript in advance.
  204. *
  205. *
  206. * @public
  207. * @langversion ActionScript 3.0
  208. * @playerversion Flash 9.0.28.0
  209. */
  210. static public var redirectFlashExceptions:Boolean = true;
  211. /**
  212. *
  213. *
  214. *
  215. * @private
  216. * @langversion ActionScript 3.0
  217. * @playerversion Flash 9.0.28.0
  218. */
  219. static private var _stage:Stage = null;
  220. /**
  221. *
  222. *
  223. *
  224. * @private
  225. * @langversion ActionScript 3.0
  226. * @playerversion Flash 9.0.28.0
  227. */
  228. static private var _root:DisplayObject = null;
  229. /**
  230. *
  231. *
  232. *
  233. * @private
  234. * @langversion ActionScript 3.0
  235. * @playerversion Flash 9.0.28.0
  236. */
  237. static private var _isHTMLTitleVerified:Boolean = false;
  238. /**
  239. * Returns TRUE if you can use JSInterface. This will occur if application will run in browser with enabled ExternalInterface.
  240. *
  241. *
  242. * @public (getter)
  243. * @return Boolean
  244. * @langversion ActionScript 3.0
  245. * @playerversion Flash 9.0.28.0
  246. */
  247. static public function get available():Boolean{
  248. var val:Boolean = ExternalInterface.available;
  249. if(val){
  250. var type:String = Capabilities.playerType;
  251. if(type != FlashPlayerType.ACTIVEX && type != FlashPlayerType.PLUGIN) val = false;
  252. }
  253. return val;
  254. }
  255. /**
  256. * Return TRUE if JSInterface is initialized.
  257. *
  258. *
  259. * @public (getter)
  260. * @return Boolean
  261. * @langversion ActionScript 3.0
  262. * @playerversion Flash 9.0.28.0
  263. */
  264. static public function get initialized():Boolean{
  265. return JSCore.initialized;
  266. }
  267. /**
  268. * Initialize JSInterface.
  269. *
  270. *
  271. * @public
  272. * @param arg Any object of DisplayObject type with access to Stage, LoaderInfo of the program or
  273. * URL line of the program. This parameter allows finding the HTML-object of the program in the
  274. * DOM-tree of the HTML-page, if no ID for the Flash Player HTML-object has been set. In case of
  275. * transferring an object of DisplayObject or LoaderInfo type related to Stage the properties
  276. * JSInterface.stage and JSInterface.root, necessary for allowing access from JavaScript environment
  277. * to Flash Player environment, will be filled in automatically.
  278. * @example Initialization example:
  279. <listing version="3.0">
  280. package {
  281. import aw.external.JSInterface;
  282. public class Test extends Sprite{
  283. public function Test():void{
  284. super();
  285. JSInterface.initialize(this, true);
  286. }
  287. }
  288. }
  289. </listing>
  290. * @param allowJSAccess Enables access from JavaScript environment into Flash Player environment.
  291. * @return void
  292. * @langversion ActionScript 3.0
  293. * @playerversion Flash 9.0.28.0
  294. */
  295. static public function initialize(arg:*=null, allowJSAccess:Boolean=false):void{
  296. JSObjectTypeMapper.initialize();
  297. coreInit(arg, allowJSAccess);
  298. }
  299. /**
  300. * Initialize core of JSInterface
  301. *
  302. *
  303. * @private
  304. * @param arg
  305. * @param allowJSAccess
  306. * @return void
  307. * @langversion ActionScript 3.0
  308. * @playerversion Flash 9.0.28.0
  309. */
  310. static private function coreInit(arg:*, allowJSAccess:Boolean):void{
  311. var url:String = '';
  312. if(arg is DisplayObject){
  313. var displayObject:DisplayObject = arg as DisplayObject;
  314. _stage = displayObject.stage;
  315. findCurrentRoot();
  316. url = displayObject.loaderInfo.url;
  317. }else if(arg is LoaderInfo){
  318. _stage = (arg as LoaderInfo).content.stage;
  319. findCurrentRoot();
  320. url = (arg as LoaderInfo).url;
  321. }else if(arg) url = arg as String;
  322. allowJavaScriptAccess = allowJSAccess;
  323. JSCore.init(url);
  324. }
  325. /**
  326. * Returns root DisplayObject
  327. *
  328. *
  329. * @private
  330. * @return void
  331. * @langversion ActionScript 3.0
  332. * @playerversion Flash 9.0.28.0
  333. */
  334. static private function findCurrentRoot():void{
  335. var len:int = _stage.numChildren;
  336. var item:DisplayObject;
  337. if(len==1) item = _stage.getChildAt(0);
  338. else{
  339. for(var i:int=0; i<len; i++){
  340. item = _stage.getChildAt(i);
  341. if(item.root && item.root!=_stage) break;
  342. }
  343. }
  344. _root = item;
  345. }
  346. /**
  347. * Current Stage object.
  348. *
  349. *
  350. * @public (getter)
  351. * @return Stage
  352. * @langversion ActionScript 3.0
  353. * @playerversion Flash 9.0.28.0
  354. */
  355. static public function get stage():Stage{
  356. return _stage;
  357. }
  358. /**
  359. *
  360. *
  361. *
  362. * @public (setter)
  363. * @param p
  364. * @return void
  365. * @langversion ActionScript 3.0
  366. * @playerversion Flash 9.0.28.0
  367. */
  368. static public function set stage(p:Stage):void{
  369. _stage = p;
  370. }
  371. /**
  372. * Root object of DisplayObject hierarchy
  373. *
  374. *
  375. * @public (getter)
  376. * @return DisplayObject
  377. * @langversion ActionScript 3.0
  378. * @playerversion Flash 9.0.28.0
  379. */
  380. static public function get root():DisplayObject{
  381. return _root;
  382. }
  383. /**
  384. *
  385. *
  386. *
  387. * @public (setter)
  388. * @param p
  389. * @return void
  390. * @langversion ActionScript 3.0
  391. * @playerversion Flash 9.0.28.0
  392. */
  393. static public function set root(p:DisplayObject):void{
  394. _root = p;
  395. }
  396. /**
  397. * Returns title of HTML page
  398. *
  399. *
  400. * @public
  401. * @param str
  402. * @return void
  403. * @langversion ActionScript 3.0
  404. * @playerversion Flash 9.0.28.0
  405. */
  406. static public function getTitle():String{
  407. return ExternalInterface.call(GET_TITLE);
  408. }
  409. /**
  410. * Setup title of HTML page
  411. *
  412. *
  413. * @public
  414. * @param str
  415. * @return void
  416. * @langversion ActionScript 3.0
  417. * @playerversion Flash 9.0.28.0
  418. */
  419. static public function setTitle(str:String):void{
  420. ExternalInterface.call(SET_TITLE, str);
  421. }
  422. /**
  423. * Returns status of HTML page
  424. *
  425. *
  426. * @public
  427. * @return String
  428. * @langversion ActionScript 3.0
  429. * @playerversion Flash 9.0.28.0
  430. */
  431. static public function getStatus():String{
  432. return ExternalInterface.call(GET_STATUS);
  433. }
  434. /**
  435. * Setup status of HTML page
  436. *
  437. *
  438. * @public
  439. * @param str
  440. * @return void
  441. * @langversion ActionScript 3.0
  442. * @playerversion Flash 9.0.28.0
  443. */
  444. static public function setStatus(str:String):void{
  445. ExternalInterface.call(SET_STATUS, str);
  446. }
  447. /**
  448. * Returns default status of HTML page
  449. *
  450. *
  451. * @public
  452. * @return String
  453. * @langversion ActionScript 3.0
  454. * @playerversion Flash 9.0.28.0
  455. */
  456. static public function getDefaultStatus():String{
  457. return ExternalInterface.call(GET_DEFAULT_STATUS);
  458. }
  459. /**
  460. * Setup default status of HTML page
  461. *
  462. *
  463. * @public
  464. * @param str
  465. * @return void
  466. * @langversion ActionScript 3.0
  467. * @playerversion Flash 9.0.28.0
  468. */
  469. static public function setDefaultStatus(str:String):void{
  470. ExternalInterface.call(SET_DEFAULT_STATUS, str);
  471. }
  472. /**
  473. * Returns URL of current HTML page on which runs this application
  474. *
  475. *
  476. * @public
  477. * @return String
  478. * @langversion ActionScript 3.0
  479. * @playerversion Flash 9.0.28.0
  480. */
  481. static public function getLocation():String{
  482. return ExternalInterface.call(GET_LOCATION);
  483. }
  484. /**
  485. * Returns URL of top level frame in current HTML page
  486. *
  487. *
  488. * @public
  489. * @return String
  490. * @langversion ActionScript 3.0
  491. * @playerversion Flash 9.0.28.0
  492. */
  493. static public function getTopLocation():String{
  494. return ExternalInterface.call(GET_TOP_LOCATION);
  495. }
  496. /**
  497. * Returns current anchor(hash from URL) from HTML page
  498. *
  499. *
  500. * @public
  501. * @return String
  502. * @langversion ActionScript 3.0
  503. * @playerversion Flash 9.0.28.0
  504. */
  505. static public function getLocationHash():String{
  506. return ExternalInterface.call(GET_LOCATION_HASH);
  507. }
  508. /**
  509. * Setup anchor for current HTML page
  510. *
  511. *
  512. * @public
  513. * @param str
  514. * @return void
  515. * @langversion ActionScript 3.0
  516. * @playerversion Flash 9.0.28.0
  517. */
  518. static public function setLocationHash(str:String):void{
  519. ExternalInterface.call(SET_LOCATION_HASH, str);
  520. }
  521. /**
  522. * Returns all cookie in string format
  523. *
  524. *
  525. * @public
  526. * @return String
  527. * @langversion ActionScript 3.0
  528. * @playerversion Flash 9.0.28.0
  529. */
  530. static public function getCookieString():String{
  531. return ExternalInterface.call(GET_COOKIE_STRING);
  532. }
  533. /**
  534. *
  535. *
  536. *
  537. * @private
  538. * @langversion ActionScript 3.0
  539. * @playerversion Flash 9.0.28.0
  540. */
  541. static private var JS_SET_COOKIE_COMMAND:String = 'document.cookie = ';
  542. /**
  543. * Setup cookie
  544. *
  545. *
  546. * @public
  547. * @param name Cookie name
  548. * @param value Cookie value
  549. * @param date Expiration date
  550. * @param path Path on which the cookie will be available
  551. * @param domain Domain for which cookie value is available
  552. * @param secure If TRUE, a cookie will be sent only via HTTPS
  553. * @return void
  554. * @langversion ActionScript 3.0
  555. * @playerversion Flash 9.0.28.0
  556. */
  557. static public function setCookie(name:*, value:*, date:Date=null, path:String='/', domain:String='', secure:Boolean=false):void{
  558. var str:String = name.toString()+'='+value.toString();
  559. if(date) str += ';expires='+date.toUTCString();
  560. if(path) str += ';path='+path;
  561. if(domain) str += ';domain='+domain;
  562. if(secure) str += ';secure';
  563. ExternalInterface.call(SET_COOKIE_STRING, str);
  564. }
  565. /**
  566. *
  567. *
  568. *
  569. * @private
  570. * @langversion ActionScript 3.0
  571. * @playerversion Flash 9.0.28.0
  572. */
  573. static private var COOKIE_SPACER:String = '; ';
  574. /**
  575. *
  576. *
  577. *
  578. * @private
  579. * @langversion ActionScript 3.0
  580. * @playerversion Flash 9.0.28.0
  581. */
  582. static private var VALUE_SPACER:String = '=';
  583. /**
  584. * Returns the cookie by its name
  585. *
  586. *
  587. * @public
  588. * @param name
  589. * @return String
  590. * @langversion ActionScript 3.0
  591. * @playerversion Flash 9.0.28.0
  592. */
  593. static public function getCookie(name:String):String{
  594. var str:String = getCookieString();
  595. if(str && name){
  596. var nlen:int = name.length;
  597. var cpos:int = 0;
  598. var spos:int = 0;
  599. while((cpos = str.indexOf(name, spos))>=0 && (str.charAt(cpos+nlen)!=VALUE_SPACER || (Boolean(cpos) && str.substr(cpos-2, 2)!=COOKIE_SPACER))){
  600. spos = cpos+nlen;
  601. }
  602. var val:String = '';
  603. if(cpos>=0){
  604. spos = cpos+nlen+1;
  605. cpos = str.indexOf(COOKIE_SPACER, spos);
  606. val = str.substring(spos, cpos<0 ? str.length : cpos);
  607. }
  608. }
  609. return val;
  610. }
  611. /**
  612. *
  613. *
  614. *
  615. * @private (constant)
  616. * @langversion ActionScript 3.0
  617. * @playerversion Flash 9.0.28.0
  618. */
  619. static private const MILLISECONDS_IN_DAY:int = 86400000;
  620. /**
  621. * Removes cookie
  622. *
  623. *
  624. * @public
  625. * @param name
  626. * @param path
  627. * @param domain
  628. * @param secure
  629. * @return void
  630. * @langversion ActionScript 3.0
  631. * @playerversion Flash 9.0.28.0
  632. */
  633. static public function removeCookie(name:*, path:String='/', domain:String='', secure:Boolean=false):void{
  634. var d:Date = new Date();
  635. d.setTime(d.getTime()-MILLISECONDS_IN_DAY);
  636. setCookie(name, '', d, path, domain, secure);
  637. }
  638. /**
  639. *
  640. *
  641. *
  642. * @private (protected)
  643. * @see aw.external.jsinterface.objects.JSWindow
  644. * @langversion ActionScript 3.0
  645. * @playerversion Flash 9.0.28.0
  646. */
  647. static protected var _window:JSWindow;
  648. /**
  649. * Reference to the JavaScript window object. This object is used in JavaScript,
  650. * as a global and globally declared JavaScript functions and properties will be
  651. * available through it, as its methods and properties
  652. *
  653. *
  654. * @public (getter)
  655. * @return JSWindow
  656. * @see aw.external.jsinterface.objects.JSWindow
  657. * @langversion ActionScript 3.0
  658. * @playerversion Flash 9.0.28.0
  659. */
  660. static public function get window():JSWindow{
  661. if(!_window){
  662. _window = JSCore.getWindow(JSWindow) as JSWindow;
  663. }
  664. return _window;
  665. }
  666. /**
  667. *
  668. *
  669. *
  670. * @private (protected)
  671. * @see aw.external.jsinterface.objects.JSDocument
  672. * @langversion ActionScript 3.0
  673. * @playerversion Flash 9.0.28.0
  674. */
  675. static protected var _document:JSDocument;
  676. /**
  677. * Reference to the JavaScript document object
  678. *
  679. *
  680. * @public (getter)
  681. * @return JSDocument
  682. * @see aw.external.jsinterface.objects.JSDocument
  683. * @langversion ActionScript 3.0
  684. * @playerversion Flash 9.0.28.0
  685. */
  686. static public function get document():JSDocument{
  687. if(!_document){
  688. _document = JSCore.getDocument(JSDocument) as JSDocument;
  689. }
  690. return _document;
  691. }
  692. /**
  693. *
  694. *
  695. *
  696. * @private (protected)
  697. * @see aw.external.jsinterface.objects.JSNavigator
  698. * @langversion ActionScript 3.0
  699. * @playerversion Flash 9.0.28.0
  700. */
  701. static protected var _navigator:JSNavigator;
  702. /**
  703. * Reference to the JavaScript navigator object
  704. *
  705. *
  706. * @public (getter)
  707. * @return JSNavigator
  708. * @see aw.external.jsinterface.objects.JSNavigator
  709. * @langversion ActionScript 3.0
  710. * @playerversion Flash 9.0.28.0
  711. */
  712. static public function get navigator():JSNavigator{
  713. if(!_navigator){
  714. _navigator = JSCore.getNavigator(JSNavigator) as JSNavigator;
  715. }
  716. return _navigator;
  717. }
  718. /**
  719. *
  720. *
  721. *
  722. * @private (protected)
  723. * @see aw.external.jsinterface.objects.JSHTMLElement
  724. * @langversion ActionScript 3.0
  725. * @playerversion Flash 9.0.28.0
  726. */
  727. static protected var _main:JSHTMLElement;
  728. /**
  729. * Reference to the JavaScript object of this copy of Flash Player, from the HTML tree
  730. *
  731. *
  732. * @public (getter)
  733. * @return JSHTMLElement
  734. * @see aw.external.jsinterface.objects.JSHTMLElement
  735. * @langversion ActionScript 3.0
  736. * @playerversion Flash 9.0.28.0
  737. */
  738. static public function get main():JSHTMLElement{
  739. if(!_main){
  740. _main = JSCore.getMain(JSHTMLElement) as JSHTMLElement;
  741. }
  742. return _main;
  743. }
  744. /**
  745. *
  746. *
  747. *
  748. * @private (protected)
  749. * @see aw.external.jsinterface.objects.JSEvent
  750. * @langversion ActionScript 3.0
  751. * @playerversion Flash 9.0.28.0
  752. */
  753. static protected var _event:JSEvent;
  754. /**
  755. * Reference to the JavaScript event object
  756. *
  757. *
  758. * @public (getter)
  759. * @return JSEvent
  760. * @see aw.external.jsinterface.objects.JSEvent
  761. * @langversion ActionScript 3.0
  762. * @playerversion Flash 9.0.28.0
  763. */
  764. static public function get event():JSEvent{
  765. if(_event) JSInstanceCache.removeFromCache(_event.js_interface::info.value);
  766. _event = JSCore.getEvent(JSEvent) as JSEvent;
  767. return _event;
  768. }
  769. /**
  770. * Clear stacks of transmitted objects
  771. *
  772. *
  773. * @public
  774. * @param flCallbacks Clear stack of functions from JavaScript
  775. * @param flObjects Clear stack of objects from JavaScript
  776. * @param jsCallbacks Clear stack of functions from Flash Player
  777. * @param jsObjects Clear stack of objects from Flash Player
  778. * @return void
  779. * @langversion ActionScript 3.0
  780. * @playerversion Flash 9.0.28.0
  781. */
  782. static public function clear(flCallbacks:Boolean=true, flObjects:Boolean=true, jsCallbacks:Boolean=true, jsObjects:Boolean=true):void{
  783. if(flObjects){
  784. _window = null;
  785. _document = null;
  786. _navigator = null;
  787. _main = null;
  788. _event = null;
  789. }
  790. JSCore.clear(flCallbacks, flObjects, jsCallbacks, jsObjects);
  791. }
  792. /**
  793. * Get value by path from JavaScript environment
  794. *
  795. *
  796. * @public
  797. * @param path
  798. * @param cls
  799. * @return *
  800. * @langversion ActionScript 3.0
  801. * @playerversion Flash 9.0.28.0
  802. */
  803. static public function getInstance(path:String, cls:Class=null):*{
  804. return JSCore.getInstance(path, cls);
  805. }
  806. /**
  807. * Load JavaScript file into the HTML document
  808. *
  809. *
  810. * @public
  811. * @param url File URL
  812. * @param func Function which will be called when load complete
  813. * @param type TYPE attribute value of SCRIPT tag, if not specified, the default will be used - "text/javascript"
  814. * @return JSHTMLElement HTML object of created SCRIPT tag
  815. * @see aw.external.jsinterface.objects.JSHTMLElement
  816. * @langversion ActionScript 3.0
  817. * @playerversion Flash 9.0.28.0
  818. */
  819. static public function loadJavaScript(url:String, func:Function=null, type:String=''):JSHTMLElement{
  820. return JSCore.loadJavaScript(url, func, type, JSHTMLElement) as JSHTMLElement;
  821. }
  822. /**
  823. * Adds new SCRIPT tag with content from "code" argument into HEAD section of HTML document
  824. * @param code JavaScript code
  825. * @param type Content of "type" argument of SCRIPT tag, by default is "text/javascript"
  826. * @param asVirual If TRUE, will NOT add new SCRIPT tag and will return NULL
  827. * @return Created tag object
  828. * @see aw.external.jsinterface.objects.JSHTMLElement
  829. * @langversion ActionScript 3.0
  830. * @playerversion Flash 9.0.28.0
  831. *
  832. */
  833. static public function pushJavaScript(code:String, type:String='', asVirual:Boolean=false):JSHTMLElement{
  834. if(asVirual){
  835. JSCore.callAnonymous(code, false);
  836. return null;
  837. }else{
  838. return JSCore.pushSCRIPTTag(code, type, JSHTMLElement) as JSHTMLElement;
  839. }
  840. }
  841. /**
  842. * Load CSS file into the HTML document
  843. *
  844. *
  845. * @public
  846. * @param url File URL
  847. * @param func Function which will be called when load complete. In a browser, Fire Fox is not called onload event, so to catch the complete of loading in such a way is impossible, and this function will not be called.
  848. * @param type TYPE attribute value of LINK tag, if not specified, the default will be used - "text/css"
  849. * @return JSHTMLElement HTML object of created LINK tag
  850. * @see aw.external.jsinterface.objects.JSHTMLElement
  851. * @langversion ActionScript 3.0
  852. * @playerversion Flash 9.0.28.0
  853. */
  854. static public function loadCSS(url:String, func:Function=null, type:String=''):JSHTMLElement{
  855. return JSCore.loadCSS(url, func, type, JSHTMLElement) as JSHTMLElement;
  856. }
  857. /**
  858. * Adds new STYLE tag with content from "style" argument into HEAD section of HTML document
  859. * @param style CSS Style definitions
  860. * @param type Content of "type" argument of STYLE tag, by default is "text/css"
  861. * @return Created tag object
  862. * @see aw.external.jsinterface.objects.JSHTMLElement
  863. * @langversion ActionScript 3.0
  864. * @playerversion Flash 9.0.28.0
  865. *
  866. */
  867. static public function pushCSS(style:String, type:String=''):JSHTMLElement{
  868. return JSCore.pushSTYLETag(style, type, JSHTMLElement) as JSHTMLElement;
  869. }
  870. /**
  871. * Call the JavaScript method by timeout
  872. *
  873. *
  874. * @public
  875. * @param obj The object containing the method
  876. * @param propName Method name
  877. * @param args Arguments list
  878. * @param func Function into which will return the result of the JavaScript function
  879. * @param timeout Time in milliseconds
  880. * @return void
  881. * @langversion ActionScript 3.0
  882. * @playerversion Flash 9.0.28.0
  883. */
  884. static public function callLater(obj:*, propName:String, args:Array=null, func:Function=null, timeout:uint=1):void{
  885. JSCore.callLater(obj, propName, args, func, timeout);
  886. }
  887. }
  888. }