如何动态地在Flex AIR应用程序运行JavaScript?

编程入门 行业动态 更新时间:2024-10-17 15:27:33
本文介绍了如何动态地在Flex AIR应用程序运行JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

什么是我可以在Flex或ActionScript AIR应用程序动态运行JavaScript的最简单的方法?

这是我到目前为止所。它不工作,但并htmlComponent.domWindow是迄今为止空:

如果(htmlComponent == NULL){     htmlComponent =新的HTML();     htmlComponent.htmlText =< HTML><脚本>中+ myJavaScript +< / SCRIPT><身体GT;< / BODY>< / HTML>中;     htmlComponent.addEventListener(完全,功能(五:事件):无效{跟踪(HTML载入完成');});     IInvalidating(htmlComponent).validateNow(); } 如果(htmlComponent.domWindow&安培;&安培; htmlComponent.domWindow.validateXML){     结果= htmlComponent.domWindow.validateXML(值); }

解决方案

您的问题,很可能是你不等待内容的加载实际加载。所以,你的code运行时,DOM仍是空的。

VAR的htmlText:字符串=< HTML><脚本>中+ myJavaScript +< / SCRIPT><身体GT;< / BODY>< / HTML>中; htmlLoader的=新的HTMLLoader(); htmlLoader.loadString(的htmlText); //添加一个完整的处理程序,并没有引用DOM,直到它完成 htmlLoader.addEventListener(引发Event.COMPLETE,loadComplete); 功能loadComplete(五:事件):无效{     如果(htmlLoader.domWindow&安培;&安培; htmlLoader.domWindow.myFunction){        //...do你需要与存在domWindow     } }

What is the easiest way I can run JavaScript dynamically in a Flex or ActionScript AIR application?

This is what I have so far. It does not work yet and htmlComponent.domWindow is so far null:

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); }

解决方案

Your issue, is likely that you do not wait for the loading of the content to actually load. So when your code runs, the DOM is still empty.

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 AIR应用程序运行JavaScript?

本文发布于:2023-11-23 16:08:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622077.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   动态   AIR   Flex   JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!