2010-03-16 17 views
0

我只需要将HTML(DOM对象)从javascript传递给Actionscript。将HTML-DOM传递给Flex的动作脚本

我看到了this article on the net并尝试了类似的代码。 但是,当我在IE中执行代码时,它会提示:“第18行的内存不足”。我从昨天开始就停留在这里。

我会后的MXML和HTML这里..

的MXML:

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> 
    <mx:Script> 
     <![CDATA[ 

      public function init() : void 
      { 
       if (ExternalInterface.available) 
       { 
        try { 
         ExternalInterface.addCallback("populateFlashFile", populateFlashFile); 
        } catch (error:SecurityError) {      
        } catch (error:Error) { 
        } 
       } 
      } 
      public function populateFlashFile(window:*) : void 
      { 
       log.text = window.toString(); // just for checking if window has come to the function. 
       window.document.write("Hello"); 
      } 
      ]]> 
      </mx:Script> 
    <mx:TextArea x="10" y="23" width="712" height="581" id="log"/> 
</mx:Application> 

的HTML:

<html lang="en"> 

<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
</head> 

<body scroll="no"> 

<input type="button" onclick="document.getElementById('Test').populateFlashFile(window);"/> 

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
      id="Test" width="100%" height="100%" 
      codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"> 
      <param name="movie" value="Test.swf" /> 
      <param name="quality" value="high" /> 
      <param name="bgcolor" value="#869ca7" /> 
      <param name="allowScriptAccess" value="sameDomain" /> 
    </object> 
</body> 
</html> 

当我通过一些DOM对象的问题只occors,如果我传递一些字符串它的作品。 例如:
<input type="button" onclick="document.getElementById('Test').populateFlashFile('some text here');"/>
很好用!

+0

或者,如果有任何其他替代方案将DOM从js传递到as,请提出建议。 – raj 2010-03-16 06:39:12

回答

0

你试图做的只有AIR才能实现。如果你重新检查你发布的链接,你应该看到。 这是因为AIR在包含的Tamarin上运行AS和JS。

据我所知,只能在JS和AS之间传递原始值,两种方式。也许数组和匿名对象,但我不会依赖于此。但是,您可以inject arbitrary JS into the containing HTML

+0

非常酷!你给的链接 - http://www.actionscript.org/resources/articles/745/3/JavaScript-and-VBScript-Injection-in-ActionScript-3/Page3.html解决了我的问题..谢谢:) – raj 2010-03-16 11:29:54