如何在 Flex AIR 应用程序中动态 运行 JavaScript?
How to run JavaScript dynamically in a Flex AIR application?
在 Flex 或 ActionScript AIR 应用程序中动态 运行 JavaScript 最简单的方法是什么?
这就是我目前所拥有的。它还不起作用,htmlComponent.domWindow 到目前为止为空:
if (htmlComponent==null) {
htmlComponent = new HTML();
htmlComponent.htmlText = "<html><script>"+myJavaScript+"</script><body></body></html>";
htmlComponent.addEventListener("complete", function(e:Event):void {trace('html load complete');});
IInvalidating(htmlComponent).validateNow();
}
if (htmlComponent.domWindow && htmlComponent.domWindow.validateXML) {
result = htmlComponent.domWindow.validateXML(value);
}
您的问题可能是您没有等待内容加载到实际加载。因此,当您的代码运行时,DOM 仍然是空的。
var htmlText:String = "<html><script>"+myJavaScript+"</script><body></body></html>";
htmlLoader = new HTMLLoader();
htmlLoader.loadString(htmlText);
// add a complete handler and don't reference the DOM until it's complete
htmlLoader.addEventListener(Event.COMPLETE, loadComplete);
function loadComplete(e:Event):void {
if (htmlLoader.domWindow && htmlLoader.domWindow.myFunction){
//...do what you need to with the domWindow
}
}
在 Flex 或 ActionScript AIR 应用程序中动态 运行 JavaScript 最简单的方法是什么?
这就是我目前所拥有的。它还不起作用,htmlComponent.domWindow 到目前为止为空:
if (htmlComponent==null) {
htmlComponent = new HTML();
htmlComponent.htmlText = "<html><script>"+myJavaScript+"</script><body></body></html>";
htmlComponent.addEventListener("complete", function(e:Event):void {trace('html load complete');});
IInvalidating(htmlComponent).validateNow();
}
if (htmlComponent.domWindow && htmlComponent.domWindow.validateXML) {
result = htmlComponent.domWindow.validateXML(value);
}
您的问题可能是您没有等待内容加载到实际加载。因此,当您的代码运行时,DOM 仍然是空的。
var htmlText:String = "<html><script>"+myJavaScript+"</script><body></body></html>";
htmlLoader = new HTMLLoader();
htmlLoader.loadString(htmlText);
// add a complete handler and don't reference the DOM until it's complete
htmlLoader.addEventListener(Event.COMPLETE, loadComplete);
function loadComplete(e:Event):void {
if (htmlLoader.domWindow && htmlLoader.domWindow.myFunction){
//...do what you need to with the domWindow
}
}