【发布时间】:2011-03-07 15:51:13
【问题描述】:
我在从我的 AIR / Flex 应用程序调用 javascript 函数时遇到问题。在 web 应用程序中,使用 externallInterface 很容易,但在本机应用程序中,这是一个问题。我的 AIR 应用程序是这样的......
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="init()" ... >
<mx:Script>
<![CDATA[
private function init():void
{
myHTML.addEventListener(Event.HTML_DOM_INITIALIZE,DOMInit);
myHTML.location="myAIRHTML.html";
}
private function DOMInit(e:Event):void{
myHTML.htmlLoader.window.inputFunction = testInputFunction;
}
private function testInputFunction(so:String):void{
//some code ......
}
public function someFunction(e:AIREvent):void{
myHTML.htmlLoader.window.outputFunction(e.param);
}
_]]>
</mx:Script>
<mx:HTML id="myHTML" width="5" height="5" visible="true" />
</mx:WindowedApplication>
myAIRHTML.html 是
<html>
<head>
<script language="Javascript">
var interface = {};
function outputFunction(param){
var childInterface = document.getElementById("mySandbox").childSandboxBridge;
childInterface.remoteFunction(param);
}
interface.inputFunction = function(someData){
testInputFunction(someData);
}
function initBridge(){
document.getElementById("mySandbox").parentSandboxBridge = interface;
}
</script>
</head>
<body>
<iframe id="mySandbox"
src="js.html"
sandboxRoot="http://remote.example.com/js/"
documentRoot="app:/myAIRSandbox/"
ondominitialize="initBridge()">
</iframe>
</body>
</html>
而 js.html 是
<html>
<head>
<script language="Javascript" src="http://www/otherexample.com/other.js"></script>
<script language="Javascript" >
var interface = {};
interface.remoteFunction = function(st){
alert("st");
callFunctionInOtherJS(st);
}
window.childSandboxBridge = interface;
var someObject = {};
someObject.SomeFunction = function(someParam){
window.parentSandboxBridge.inputFunction(someParam);
}
</script>
</head>
<body ></body>
</html>
当我在 myAIRHTML.html 中调用“remoteFunction”时,这会抛出“TypeError: Undefined value”。我错过了什么重要的事情?任何人都可以帮忙吗?重要的是我忘记了 documentRoot - 我不在其他地方使用这个名字.....感谢所有回复
【问题讨论】:
标签: javascript apache-flex flex3 air