Subscribe

  • Subscribe  

Call an ActionScript Function from JavaScript Embedded in an AIR App

Posted by Jay | April 15, 2008 .

Whoever said that becoming the master of one was more important than being the jack of many definitely did not belong to the world of computer programming. Well, this thought occurred to me when for a particular program, I was required to call one of the ActionScript functions from some JavaScript. The main problem was that this JavaScript was embedded in some HTML code that worked as the control in a Adobe AIR application. I tried the time-tested runtime.myASFunction(). And, as you must have already guessed, I failed miserably. If only it were that simple. I went through some books and tried a combination of commands but to no avail.

Then, after asking a few of my mates, I finally approached the AIR team with my problem, and luckily for me, they got back to me promptly with the solution to my problem.

They suggested a two-step solution to my problem. First, they asked me to set the domain for my html control. They told me that this can be done by using the following bit of code:

  import flash.system.ApplicationDomain;

  htmlcontrol.useApplicationDomain = ApplicationDomain.currentDomain;

The second step was to call the required function from the Javascript code. That could be done by using the following instruction:

   runtime.mx.core.Application.application.myASFunction();

I could now call the required Actionscript function easily and move ahead with my program. Well, this definitely made my life easier. Kudos to the AIR team.

I hope that this bit of code helps many like me who are stuck at the very same point!

Leave a Comment

If you would like to make a comment, please fill out the form below.


Name

Email

Website

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Comments

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word


Related Posts

3 Comments so far
  1. Guillaume  September 14, 2008 4:14 pm

    Hi this is exacly what i am trying to do but the useApplicationDomain property does not exists for mx:html object!!!

    do you have a complete source code of a working example?

    Thank you

  2. Anonymous  November 10, 2008 3:13 pm

    Thank you very much. I’ve been looking for this.

  3. Manish Bhardwaj  February 21, 2012 7:02 am

    Hi,

    thanks for your post. but it seems not working for me as useApplicationDomain property is not available in <mx:HTML component.

    could you please help me to identify how to get this thing working.

    Thanks

<

Direct TV Offers - usdirect has the best directtv deals