The recent project has used the air to read the JS file needs, research, to share the next.
Air provides the Htmlloader class, you can read the HTML file in the JS method, when you load the HTML in, you can get the JS file by Htmlloader the properties and methods provided,
Here's how.
Write as File
Private varHtml:htmlloader =NewHTMLLoader ();Private varUrlreq:urlrequest =NewURLRequest ("Assets/test.html"); Private functionStartloadjs ():void{Html.addeventlistener (event.complete, LoadComplete); Html.load (Urlreq); }Private functionLoadComplete (e:event):void{trace (HTML.WINDOW.BBQ); Trace (Html.window.transToDB ("a curved river."));}
Then write an HTML file to be placed in the Aeests directory, the file can contain or can include JS code
<script> var bbq = "O,thank You" function transtodb (str) { Return "before brother" +str; } </script>
Operation Result:
"O,thank You" "a curved river in front of my brother."
When I try to change test.html name to test.js or other extension, I can't implement
Official explanation: On desktop computers (in desktop and extended desktop profiles), the HTMLLoader class uses the internal AIR WebKit engine.
It has the same functionality and rendering appearance as the Stagewebview class, and it implements tight integration and script bridging between ActionScript and JavaScript.
Because the Stagewebview class uses the system Web controls provided by the Flash Player plug-in, it is strongly recommended that you do not use both Stagewebview and HTMLLoader instances, otherwise undefined behavior can occur, which may cause the application to terminate.
Visible, want to read JS inside the method, can only support the extension of HTML.
Ways to read JavaScript in air