我只需要將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');"/>
很好用!
或者,如果有任何其他替代方案將DOM從js傳遞到as,請提出建議。 – raj 2010-03-16 06:39:12