2010-03-16 3 views
0

원하는 것은 자바 스크립트에서 Actionscript로 HTML (DOM 객체)을 전달하는 것입니다.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로 : 내가 어떤 DOM 객체 통과 할 때 문제는 occors

<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> 

, 만약 내가 어떤 문자열을 전달하면 작동합니다. !!! 예 :
<input type="button" onclick="document.getElementById('Test').populateFlashFile('some text here');"/>
위대한 작품!

+0

또는 js에서 as로 DOM을 전달하는 다른 대안이있는 경우 제안하십시오. – raj

답변

0

당신이하려고하는 것은 AIR에서만 가능합니다. 게시 한 링크를 재검토하면 볼 수 있습니다. AIR는 AS와 JS가 포함 된 Tamarin에서 실행되기 때문입니다.

내가 아는 한 JS와 AS 사이의 원시 값만 전달할 수 있습니다. 어쩌면 배열과 익명의 객체 일지 모르지만 나는 그것에 의존하지 않을 것입니다.

그러나 inject arbitrary JS into the containing HTML 수 있습니다.

+0

매우 근사합니다! 링크 u는 준 - http://www.actionscript.org/resources/articles/745/3/JavaScript-and-VBScript-Injection-in-ActionScript-3/Page3.html 내 문제를 해결 .. 감사합니다 :) – raj