开发者

Pass HTML-DOM to Flex's actionscript

All i want is to pass a HTML (DOM object) from javascript to Actionscript.

i saw this article on the net and tried a similar code. But when i execute the code in IE, it alerts : "Out of memory at line 18". I'm stuck here from yesterday.

i'll post the mxml and html here..

The MXML :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
    <mx:Script>
 开发者_Go百科       <![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>

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

The problem occors only when i pass some DOM object, if i pass some String it works.!!! i.e :

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

works great!


what you are trying to do is only possible with AIR. if you reexamine the link you posted, you should see. This is because AIR runs both AS and JS on the included Tamarin.

as far as I know, you can only pass primitive values between JS and AS, both ways. Maybe arrays and anonymous objects, but I wouldn't rely on that.

however, you can inject arbitrary JS into the containing HTML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜