Ways to read JavaScript in air

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.