PageRenderTime 2428ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/source/full/aw/external/jsinterface/JSDynamic.as

http://jsinterface.googlecode.com/
ActionScript | 862 lines | 234 code | 47 blank | 581 comment | 30 complexity | 5ce1d04725d2775f91219b931f0f86d2 MD5 | raw file
  1. package aw.external.jsinterface{
  2. import aw.external.*;
  3. import aw.external.jsinterface.objects.JSObjectTypeMapper;
  4. import aw.utils.MethodCaller;
  5. import aw.utils.StringUtils;
  6. import flash.external.ExternalInterface;
  7. import flash.utils.Proxy;
  8. import flash.utils.flash_proxy;
  9. import flash.utils.getQualifiedClassName;
  10. /**
  11. * It’s a wrapper object for all objects transferred from JavaScript environment to Flash Player environment.
  12. * It works as an object mirror (proxy), and you can get access to any properties of the original JavaScript
  13. * object though it, call for its methods and create new JavaScript objects.
  14. *
  15. * @example Example of creating JavaScript objects:
  16. <listing version="3.0">
  17. package {
  18. import aw.external.JSInterface;
  19. import aw.external.jsinterface.JSDynamic;
  20. import flash.display.Sprite;
  21. public class Test extends Sprite{
  22. public function Test():void{
  23. super();
  24. JSInterface.initialize(true);
  25. var request:JSDynamic;
  26. if('XMLHttpRequest' in JSInterface.window){
  27. request = new JSDynamic("XMLHttpRequest");
  28. }else if('ActiveXObject' in JSInterface.window){
  29. request = new JSDynamic("ActiveXObject", "Msxml2.XMLHTTP");
  30. if(!request) request = new JSDynamic("ActiveXObject", "Microsoft.XMLHTTP");
  31. }
  32. request.open('GET', 'http://some.server.com', true);
  33. request.send(null);
  34. }
  35. }
  36. }
  37. </listing>
  38. * @example Example of getting a reference to the existing JavaScript objects:
  39. <listing version="3.0">
  40. package {
  41. import aw.external.JSInterface;
  42. import aw.external.jsinterface.JSDynamic;
  43. import aw.external.jsinterface.objects.JSHTMLElement;
  44. import flash.display.Sprite;
  45. public class Test extends Sprite{
  46. public function Test():void{
  47. super();
  48. JSInterface.initialize(true);
  49. // JavaScript object using standard JSDynamic
  50. var object1:JSDynamic = JSInterface.getInstance('window.document.body.firstChild');
  51. // JavaScript object using the class extended from JSDynamic
  52. var object2:JSHTMLElement = JSInterface.getInstance('window.document.body.firstChild', JSHTMLElement);
  53. // Return type Object, but it's JSDynamic
  54. var object3:Object = JSInterface.window.document.body.firstChild;
  55. // Conversion of wrapper type of JavaScript object from JSDynamic in JSHTMLElement (this will not affect the original object in JavaScript)
  56. var object4:JSHTMLElement = JSDynamic.convert(object1, JSHTMLElement);
  57. }
  58. }
  59. }
  60. </listing>
  61. * This object is also the basic one for all specialized wrapper objects to such JavaScript objects as
  62. * HTMLElement, Document, Navigator etc. This class can be extended for specific objects, for example,
  63. * for special objects of JavaScript framework, to announce its properties and set types for the
  64. * properties (types mapping). Upon extension of the class for properties’ types mapping it’s necessary to
  65. * indicate the properties’ types by name in JSObjectTypeMapper class, by the name of the new class, before
  66. * addressing the properties.
  67. *
  68. * Each instance of this class, created for a new JavaScript object, will be cashed in JSInstanceCache class,
  69. * but if one more JSDynamic object will be created for the same object, then the new JSDynamic object will
  70. * replace the previous instance in cash.
  71. * @example Example showing the work of caching:
  72. <listing version="3.0">
  73. package {
  74. import aw.external.JSInterface;
  75. import aw.external.jsinterface.JSDynamic;
  76. import aw.external.jsinterface.objects.JSHTMLElement;
  77. import flash.display.Sprite;
  78. public class Test extends Sprite{
  79. public function Test():void{
  80. super();
  81. JSInterface.initialize(true);
  82. var htmlTag1:JSHTMLElement = JSInterface.getInstance('window.document.body.firstChild', JSHTMLElement);
  83. var htmlTag2:Object = JSInterface.document.body.firstChild;
  84. // return TRUE because the second time the object passed JSHTMLElement for JavaScript object will not be created - would be received a copy from the cache.
  85. trace(htmlTag1===htmlTag2);
  86. }
  87. }
  88. }
  89. </listing>
  90. *
  91. * @see aw.external.jsinterface.JSTypeMap Examples of specifying the types of properties for a class extending JSDynamic
  92. * @see aw.external.jsinterface.objects.JSObjectTypeMapper
  93. *
  94. * @public
  95. * @author Galaburda a_[w] Oleg http://www.actualwave.com
  96. */
  97. public dynamic class JSDynamic extends Proxy{
  98. JSFunction;
  99. /**
  100. *
  101. *
  102. *
  103. * @public (constant)
  104. * @langversion ActionScript 3.0
  105. * @playerversion Flash 9.0.28.0
  106. */
  107. static public const CLASS_NAME:String = 'Object';
  108. /**
  109. *
  110. *
  111. *
  112. * @private (constant)
  113. * @langversion ActionScript 3.0
  114. * @playerversion Flash 9.0.28.0
  115. */
  116. static public const FUNCTION_TARGET_NAME:String = 'jsDynamicTarget';
  117. /**
  118. *
  119. *
  120. *
  121. * @private (constant)
  122. * @langversion ActionScript 3.0
  123. * @playerversion Flash 9.0.28.0
  124. */
  125. static public const DO_NOT_CREATE_OBJECT:Class = DoNotCreateObject;
  126. /**
  127. *
  128. *
  129. *
  130. * @private (constant)
  131. * @langversion ActionScript 3.0
  132. * @playerversion Flash 9.0.28.0
  133. */
  134. static public const VALUE_PROP:String = 'value';
  135. /**
  136. *
  137. *
  138. *
  139. * @private (constant)
  140. * @langversion ActionScript 3.0
  141. * @playerversion Flash 9.0.28.0
  142. */
  143. static public const INSTANCE_ERROR:String = 'JavaScript object [{$0}] instance can\'t be created.';
  144. /**
  145. *
  146. *
  147. *
  148. * @private (protected)
  149. * @see aw.external.jsinterface.JSInfoObject
  150. * @langversion ActionScript 3.0
  151. * @playerversion Flash 9.0.28.0
  152. */
  153. protected var _info:JSInfoObject;
  154. /**
  155. *
  156. *
  157. *
  158. * @private (protected)
  159. * @langversion ActionScript 3.0
  160. * @playerversion Flash 9.0.28.0
  161. */
  162. protected var _forEachCallback:Function;
  163. /**
  164. *
  165. *
  166. *
  167. * @private (protected)
  168. * @langversion ActionScript 3.0
  169. * @playerversion Flash 9.0.28.0
  170. */
  171. protected var _forInProperties:Array;
  172. /**
  173. *
  174. *
  175. *
  176. * @private (protected)
  177. * @see aw.external.jsinterface.JSTypeMap
  178. * @langversion ActionScript 3.0
  179. * @playerversion Flash 9.0.28.0
  180. */
  181. protected var _typeMap:JSTypeMap;
  182. /**
  183. * The Constructor assumes the name of the JavaScript object class and the array of arguments for the constructor
  184. * of the JavaScript object being created. The created JSDynamic object will be the wrapper for the created JavaScript object.
  185. * A JavaScript function (transferred to Flash Player environment earlier) can be transferred instead of class name, in this
  186. * case this function will be used as the new object constructor upon creation of a new object. Another JSDynamic object can be
  187. * also transferred instead of class name, in this case a new object of the same type will be created. A utility object of
  188. * JSInfoObject type used for service purposes for creating wrapper to existing objects can also be transferred.
  189. *
  190. * @public
  191. * @param className JavaScript class name, JavaScript function, or other object JSDynamic
  192. * @param args The list of arguments to the JavaScript object constructor or argument value, if only one
  193. * @return void
  194. * @langversion ActionScript 3.0
  195. * @playerversion Flash 9.0.28.0
  196. */
  197. public function JSDynamic(className:Object=CLASS_NAME, args:*=null):void{
  198. super();
  199. if(className && className!==DO_NOT_CREATE_OBJECT){
  200. if(arguments.length>1 && !(args is Array)) args = [args];
  201. js_interface::createInfo(className, args);
  202. }
  203. init();
  204. }
  205. /**
  206. * Initialize the object and receiving the type map
  207. *
  208. *
  209. * @private (protected)
  210. * @return void
  211. * @langversion ActionScript 3.0
  212. * @playerversion Flash 9.0.28.0
  213. */
  214. protected function init():void{
  215. _typeMap = JSObjectTypeMapper.getMapByObject(this);
  216. }
  217. /**
  218. * Creates a JavaScript object or get information about existing JavaScript object
  219. *
  220. *
  221. * @public (js_interface)
  222. * @param className
  223. * @param args
  224. * @return void
  225. * @langversion ActionScript 3.0
  226. * @playerversion Flash 9.0.28.0
  227. */
  228. js_interface function createInfo(className:Object, args:Array=null):void{
  229. var obj:Object;
  230. if(className is Function && FUNCTION_TARGET_NAME in className){
  231. obj = JSCore.createObjectByLink(className[FUNCTION_TARGET_NAME] as JSDynamic, args);
  232. }else if(className is JSDynamic){
  233. obj = JSCore.createObjectByLink(className as JSDynamic, args);
  234. }else if(className is JSInfoObject){
  235. obj = className;
  236. }else obj = JSCore.createObject(String(className), args);
  237. if(obj && VALUE_PROP in obj){
  238. this._info = (obj is JSInfoObject) ? obj as JSInfoObject : new JSInfoObject(obj);
  239. JSInstanceCache.addToCache(obj.value, this);
  240. }else throw new Error(StringUtils.createByTemplate(INSTANCE_ERROR, className));
  241. }
  242. /**
  243. * String reference to the JavaScript object in stack of transmitted objects
  244. *
  245. *
  246. * @public (js_interface,getter)
  247. * @return String
  248. * @langversion ActionScript 3.0
  249. * @playerversion Flash 9.0.28.0
  250. */
  251. js_interface function get name():String{
  252. return this._info.value;
  253. }
  254. /**
  255. *
  256. *
  257. *
  258. * @public (js_interface,setter)
  259. * @param p
  260. * @return void
  261. * @langversion ActionScript 3.0
  262. * @playerversion Flash 9.0.28.0
  263. */
  264. js_interface function set name(p:String):void{
  265. this._info.value = p;
  266. }
  267. /**
  268. * Info object of passed object
  269. *
  270. *
  271. * @public (js_interface,getter)
  272. * @return JSInfoObject
  273. * @see aw.external.jsinterface.JSInfoObject
  274. * @langversion ActionScript 3.0
  275. * @playerversion Flash 9.0.28.0
  276. */
  277. js_interface function get info():JSInfoObject{
  278. return this._info;
  279. }
  280. /**
  281. *
  282. *
  283. *
  284. * @public (js_interface,setter)
  285. * @param p
  286. * @return void
  287. * @see aw.external.jsinterface.JSInfoObject
  288. * @langversion ActionScript 3.0
  289. * @playerversion Flash 9.0.28.0
  290. */
  291. js_interface function set info(p:JSInfoObject):void{
  292. if(p){
  293. var name:String = p.value;
  294. JSInstanceCache.removeFromCache(name);
  295. this._info = p;
  296. JSInstanceCache.addToCache(name, this);
  297. }
  298. }
  299. /**
  300. * Get the value by path from JavaScript Object
  301. *
  302. * @example
  303. <listing version="3.0">
  304. package {
  305. import aw.external.JSInterface;
  306. import aw.external.js_interface;
  307. import aw.external.jsinterface.objects.JSHTMLElement;
  308. import flash.display.Sprite;
  309. public class Test extends Sprite{
  310. public function Test():void{
  311. super();
  312. JSInterface.initialize(this, true);
  313. // Obtain the value of the string path to an object
  314. var element:JSHTMLElement = JSInterface.document.js_interface::getValue("body.childNodes[1]", JSHTMLElement);
  315. trace(element); // [object]
  316. }
  317. }
  318. }
  319. </listing>
  320. * @public (js_interface)
  321. * @param path
  322. * @param cls
  323. * @return *
  324. * @langversion ActionScript 3.0
  325. * @playerversion Flash 9.0.28.0
  326. */
  327. js_interface function getValue(path:String, cls:Class=null):*{
  328. return JSCore.getParamValue(this, path, cls);
  329. }
  330. /**
  331. * Returns a list of the names of the properties of JavaScript object
  332. *
  333. *
  334. * @public (js_interface,getter)
  335. * @return Array
  336. * @langversion ActionScript 3.0
  337. * @playerversion Flash 9.0.28.0
  338. */
  339. js_interface function get properties():Array{
  340. return JSCore.propertyList(this._info.value);
  341. }
  342. /**
  343. * Used for “transformation” of JSDynamic object to a function in cases when a reference to function was
  344. * transferred from JavaScript environment. Getting an object of JSDynamic type instead of a Function from
  345. * JavaScript can prevent using it, that’s why the received JSDynamic automatically turns into a function
  346. * and the developers gets a possibility to use a JavaScript function in Flash Player environment as a usual
  347. * function. All calls for such function will be sent to JavaScript environment and executed as usual function
  348. * calls. This function works automatically, there is no need to call for it yourself.
  349. *
  350. * This function has additional methods, besides the standard Function.call() and Function.apply():
  351. * <ul>
  352. * <li>Function.remove() – removes JavaScript function from the stack of transferred functions.</li>
  353. * <li>Function.isExists() – checks for presence of a JavaScript function in the stack.</li>
  354. * </ul>
  355. * @private (js_interface)
  356. * @return Function
  357. * @langversion ActionScript 3.0
  358. * @playerversion Flash 9.0.28.0
  359. */
  360. js_interface function asFunction():Function{
  361. var f:Object = function(a:*, b:*, c:*, d:*, e:*, f:*, g:*, h:*, i:*, j:*, k:*, l:*, m:*, n:*, o:*, p:*, q:*, r:*, s:*, t:*, u:*, v:*, w:*, x:*, y:*, z:*):*{
  362. var name:String = arguments.callee.name;
  363. if(!this || !(this is JSDynamic)){
  364. return JSCore.callFunction(name, '', arguments);
  365. }else{
  366. return JSCore.callFunction(name, this.js_interface::name, arguments);
  367. }
  368. }
  369. var name:String = this.js_interface::name;
  370. f.remove = function():void{
  371. var name:String = arguments.callee.name;
  372. JSCore.removeFunction(name);
  373. }
  374. f.remove.name = name;
  375. f.isExists = function():Boolean{
  376. var name:String = arguments.callee.name;
  377. return JSCore.functionExists(name);
  378. }
  379. f.isExists.name = name;
  380. f.name = name;
  381. f[FUNCTION_TARGET_NAME] = this;
  382. return f as Function;
  383. }
  384. /**
  385. *
  386. *
  387. *
  388. * @private (constant)
  389. * @langversion ActionScript 3.0
  390. * @playerversion Flash 9.0.28.0
  391. */
  392. static private const CURRENT_CALLBACK_NAME:QName = new QName(js_interface, 'currentCallback');
  393. /**
  394. * The property is open for internal usage. Use for temporary storage of anonymous functions.
  395. *
  396. *
  397. * @private (js_interface)
  398. * @langversion ActionScript 3.0
  399. * @playerversion Flash 9.0.28.0
  400. */
  401. js_interface var currentCallback:Function;
  402. /**
  403. * Method for internal use - calls a temporary, anonymous function in the scope of the object, without using Function.call() and Function.apply().
  404. *
  405. *
  406. * @private (js_interface)
  407. * @param f
  408. * @param args
  409. * @return *
  410. * @langversion ActionScript 3.0
  411. * @playerversion Flash 9.0.28.0
  412. */
  413. js_interface function callCallback(f:Function, args:Array):*{
  414. this.js_interface::currentCallback = f;
  415. var value:*;
  416. if(args is JSArguments){
  417. value = MethodCaller.callByName(this, CURRENT_CALLBACK_NAME, args);
  418. }else{
  419. value = MethodCaller.applyByName(this, CURRENT_CALLBACK_NAME, args);
  420. }
  421. this.js_interface::currentCallback = null;
  422. return value;
  423. }
  424. /**
  425. * Cycle properties of JavaScript object using the callback function
  426. *
  427. *
  428. * @public (js_interface)
  429. * @param callbackFunction Callback function
  430. * @param useList If you specify TRUE, it will be used for not "live" cycle, a sort out of properties in the Flash Player environment with the list of property names.
  431. * @return void
  432. * @langversion ActionScript 3.0
  433. * @playerversion Flash 9.0.28.0
  434. */
  435. js_interface function forEach(callbackFunction:Function, useList:Boolean=false):void{
  436. var name:String;
  437. if(!JSCore.hasDocument() || useList){
  438. var arr:Array = this.js_interface::properties;
  439. var len:int = arr.length;
  440. for(var i:int=0; i<len; i++){
  441. name = arr[i];
  442. callbackFunction(this, name, this.flash_proxy::getProperty(name));
  443. }
  444. }else{
  445. this._forEachCallback = callbackFunction;
  446. name = JSCaller.addForEachHandler(this.jsForEachCallback);
  447. JSCore.forEach(this._info.value, name);
  448. JSCaller.removeForEachHandler(name);
  449. this._forEachCallback = null;
  450. }
  451. }
  452. /**
  453. * Remove JavaScript object from the stack
  454. *
  455. *
  456. * @public (js_interface)
  457. * @return void
  458. * @langversion ActionScript 3.0
  459. * @playerversion Flash 9.0.28.0
  460. */
  461. js_interface function remove():void{
  462. var n:String = this._info.value;
  463. JSInstanceCache.removeFromCache(n);
  464. JSCore.removeObject(n);
  465. }
  466. /**
  467. * Verifies the existence of JavaScript object in the stack
  468. *
  469. *
  470. * @public (js_interface)
  471. * @return Boolean
  472. * @langversion ActionScript 3.0
  473. * @playerversion Flash 9.0.28.0
  474. */
  475. js_interface function isExists():Boolean{
  476. return JSCore.objectExists(this._info.value);
  477. }
  478. /**
  479. * Verifies references to JavaScript objects and returns TRUE, if the links are identical, ie refer to the same object
  480. *
  481. *
  482. * @public (js_interface)
  483. * @param jsd
  484. * @return Boolean
  485. * @see aw.external.jsinterface.JSDynamic
  486. * @langversion ActionScript 3.0
  487. * @playerversion Flash 9.0.28.0
  488. */
  489. js_interface function isEqual(jsd:JSDynamic):Boolean{
  490. return (jsd && this._info.value==jsd.js_interface::name);
  491. }
  492. /**
  493. *
  494. *
  495. *
  496. * @private (protected)
  497. * @param param
  498. * @param value
  499. * @return void
  500. * @langversion ActionScript 3.0
  501. * @playerversion Flash 9.0.28.0
  502. */
  503. protected function jsForEachCallback(param:String, value:*):void{
  504. this._forEachCallback(this, param, value);
  505. }
  506. //------------------------------------ Proxy
  507. /**
  508. *
  509. *
  510. *
  511. * @private (flash_proxy)
  512. * @param name
  513. * @param args
  514. * @return *
  515. * @langversion ActionScript 3.0
  516. * @playerversion Flash 9.0.28.0
  517. */
  518. override flash_proxy function callProperty(name:*, ... args):*{
  519. return this.internalCall(name, args);
  520. }
  521. /**
  522. *
  523. *
  524. *
  525. * @private (protected)
  526. * @param name
  527. * @param args
  528. * @param cls
  529. * @return *
  530. * @langversion ActionScript 3.0
  531. * @playerversion Flash 9.0.28.0
  532. */
  533. protected function internalCall(name:*, args:Array, cls:Class=null):*{
  534. //trace(name);
  535. if(!cls){
  536. cls = this._typeMap ? this._typeMap.getType(name) : JSDynamic;
  537. //trace(getQualifiedClassName(this), this._typeMap);
  538. }
  539. var val:* = JSCore.callProperty(this.js_interface::name, this._info.type, name, args, cls);
  540. return val;
  541. }
  542. /**
  543. *
  544. *
  545. *
  546. * @private (flash_proxy)
  547. * @param name
  548. * @return *
  549. * @langversion ActionScript 3.0
  550. * @playerversion Flash 9.0.28.0
  551. */
  552. override flash_proxy function getProperty(name:*):*{
  553. return this.internalGet(name);
  554. }
  555. /**
  556. *
  557. *
  558. *
  559. * @private (protected)
  560. * @param name
  561. * @param cls
  562. * @return *
  563. * @langversion ActionScript 3.0
  564. * @playerversion Flash 9.0.28.0
  565. */
  566. protected function internalGet(name:*, cls:Class=null):*{
  567. //trace(name);
  568. var value:Object = ExternalInterface.call(JSCaller.getPropertyMethod, JSCore.name, this.js_interface::name, this._info.type, name.toString());
  569. if(JSCore.ERROR_PARAM in value){
  570. JSCaller.throwException(value.error);
  571. return undefined;
  572. }else value = value.value;
  573. //trace(obj);
  574. //trace(this._typeMap, this._typeMap.getType(name));
  575. if(value){
  576. if(!cls){
  577. cls = this._typeMap ? this._typeMap.getType(name) : JSDynamic;
  578. }
  579. var ret:* = JSInfoObject.convert(value, cls);
  580. //trace(getQualifiedClassName(this), name, value, value.value, this._typeMap, this._typeMap.getType(name), getQualifiedClassName(ret));
  581. return ret;
  582. }else return value;
  583. }
  584. /**
  585. *
  586. *
  587. *
  588. * @private (flash_proxy)
  589. * @param name
  590. * @return Boolean
  591. * @langversion ActionScript 3.0
  592. * @playerversion Flash 9.0.28.0
  593. */
  594. override flash_proxy function hasProperty(name:*):Boolean{
  595. return this.internalHas(name);
  596. }
  597. /**
  598. *
  599. *
  600. *
  601. * @private (protected)
  602. * @param name
  603. * @return Boolean
  604. * @langversion ActionScript 3.0
  605. * @playerversion Flash 9.0.28.0
  606. */
  607. protected function internalHas(name:*):Boolean{
  608. var ret:Object = ExternalInterface.call(JSCaller.hasPropertyMethod, JSCore.name, this.js_interface::name, this._info.type, name.toString());
  609. if(JSCore.ERROR_PARAM in ret){
  610. JSCaller.throwException(ret.error);
  611. }else{
  612. return ret.value;
  613. }
  614. return false;
  615. }
  616. /**
  617. *
  618. *
  619. *
  620. * @private (flash_proxy)
  621. * @param name
  622. * @return Boolean
  623. * @langversion ActionScript 3.0
  624. * @playerversion Flash 9.0.28.0
  625. */
  626. override flash_proxy function deleteProperty(name:*):Boolean{
  627. return this.internalDelete(name);
  628. }
  629. /**
  630. *
  631. *
  632. *
  633. * @private (protected)
  634. * @param name
  635. * @return Boolean
  636. * @langversion ActionScript 3.0
  637. * @playerversion Flash 9.0.28.0
  638. */
  639. protected function internalDelete(name:*):Boolean{
  640. var ret:Object = ExternalInterface.call(JSCaller.deletePropertyMethod, JSCore.name, this.js_interface::name, this._info.type, name.toString());
  641. if(JSCore.ERROR_PARAM in ret){
  642. JSCaller.throwException(ret.error);
  643. }else{
  644. return ret.value;
  645. }
  646. return false;
  647. }
  648. /**
  649. *
  650. *
  651. *
  652. * @private (flash_proxy)
  653. * @param name
  654. * @param value
  655. * @return void
  656. * @langversion ActionScript 3.0
  657. * @playerversion Flash 9.0.28.0
  658. */
  659. override flash_proxy function setProperty(name:*, value:*):void{
  660. this.internalSet(name, value);
  661. }
  662. /**
  663. *
  664. *
  665. *
  666. * @private (protected)
  667. * @param name
  668. * @param value
  669. * @return void
  670. * @langversion ActionScript 3.0
  671. * @playerversion Flash 9.0.28.0
  672. */
  673. protected function internalSet(name:*, value:*):void{
  674. var ret:Object = ExternalInterface.call(JSCaller.setPropertyMethod, JSCore.name, this.js_interface::name, this._info.type, name.toString(), JSInfoObject.create(value));
  675. if(JSCore.ERROR_PARAM in ret){
  676. JSCaller.throwException(ret.error);
  677. }
  678. }
  679. /**
  680. *
  681. *
  682. *
  683. * @private (flash_proxy)
  684. * @param index
  685. * @return int
  686. * @langversion ActionScript 3.0
  687. * @playerversion Flash 9.0.28.0
  688. */
  689. override flash_proxy function nextNameIndex(index:int):int{
  690. if (index==0){
  691. this._forInParameters = this.js_interface::properties;
  692. }
  693. if(index<this._forInParameters.length){
  694. return index+1;
  695. }else{
  696. return 0;
  697. }
  698. }
  699. /**
  700. *
  701. *
  702. *
  703. * @private (flash_proxy)
  704. * @param index
  705. * @return String
  706. * @langversion ActionScript 3.0
  707. * @playerversion Flash 9.0.28.0
  708. */
  709. override flash_proxy function nextName(index:int):String{
  710. return this._forInParameters[index-1];
  711. }
  712. /**
  713. *
  714. *
  715. *
  716. * @private (flash_proxy)
  717. * @param index
  718. * @return *
  719. * @langversion ActionScript 3.0
  720. * @playerversion Flash 9.0.28.0
  721. */
  722. override flash_proxy function nextValue(index:int):*{
  723. return this.flash_proxy::getProperty(this._forInParameters[index-1]);
  724. }
  725. /**
  726. *
  727. *
  728. *
  729. * @public
  730. * @param className
  731. * @param args
  732. * @param cls
  733. * @return JSDynamic
  734. * @see aw.external.jsinterface.JSDynamic
  735. * @langversion ActionScript 3.0
  736. * @playerversion Flash 9.0.28.0
  737. */
  738. static public function create(className:String, args:Array=null, cls:Class=null):JSDynamic{
  739. var obj:Object = JSCore.createObject(className, args);
  740. var jsd:JSDynamic = new (cls ? cls : JSDynamic)(DO_NOT_CREATE_OBJECT);
  741. jsd.js_interface::info = (obj is JSInfoObject) ? obj as JSInfoObject : new JSInfoObject(obj);
  742. return jsd;
  743. }
  744. /**
  745. * Converts an object of JSDynamic type in extended type
  746. *
  747. * @example
  748. <listing version="3.0">
  749. package {
  750. import aw.external.JSInterface;
  751. import aw.external.jsinterface.JSDynamic;
  752. import aw.external.jsinterface.objects.JSDocument;
  753. import flash.display.Sprite;
  754. public class Test extends Sprite{
  755. public function Test():void{
  756. super();
  757. JSInterface.initialize(true);
  758. var jsObject:JSDynamic = JSInterface.getInstance('window.document');
  759. var document:JSDocument = JSDynamic.convert(jsObject, JSDocument);
  760. }
  761. }
  762. }
  763. </listing>
  764. * @public
  765. * @param jsd
  766. * @param cls
  767. * @return *
  768. * @see aw.external.jsinterface.JSDynamic
  769. * @langversion ActionScript 3.0
  770. * @playerversion Flash 9.0.28.0
  771. */
  772. static public function convert(jsd:JSDynamic, cls:Class):*{
  773. if(getQualifiedClassName(jsd)==getQualifiedClassName(cls)) return jsd;
  774. else{
  775. return JSInstanceCache.getByInfo(jsd.js_interface::info, cls);
  776. }
  777. }
  778. /**
  779. * Returns the JSDynamic object of JavaScript function
  780. *
  781. *
  782. * @public
  783. * @param f
  784. * @return JSDynamic
  785. * @see aw.external.jsinterface.JSDynamic
  786. * @langversion ActionScript 3.0
  787. * @playerversion Flash 9.0.28.0
  788. */
  789. static public function convertFunctionToObject(f:Function):JSDynamic{
  790. var jsd:JSDynamic;
  791. if(f!=null && FUNCTION_TARGET_NAME in f){
  792. jsd = (f as Object)[FUNCTION_TARGET_NAME];
  793. }
  794. return jsd;
  795. }
  796. }
  797. }
  798. /**
  799. *
  800. *
  801. *
  802. * @public
  803. * @author Galaburda a_[w] Oleg http://www.actualwave.com
  804. */
  805. class DoNotCreateObject extends Object{}