JavaScript in Flash

I have a java script code that works fine when run through a browser, is there a way that I can use this code in flash without a lot of editing, I want to get input from the user through flash and have the code do the calculations and display the result in flash, any clues?

+1


source to share


3 answers


Well, ActionScript 1 is essentially javascript and 2 is just syntactic sugar on top of it. If you are making Flash 8 or earlier, you should be able to use javascript code without much customization (preferably moving to using classes instead of prototype). Moving it to ActionScript 3 (for Flash 9 or later) would have been a little more difficult as it is more strict about types and so on, but still probably not too difficult.

As mentioned, the UI stuff in Flash differs from Javascript because there is no DOM. I assumed that the methods you talked about are for performing calculations and are not related to the user interface at all. If your javascript methods actually render the UI stuff, then moving them into Flash will be much more attractive.



Another possibility, if you want to keep your code in javascript (perhaps so you can reuse it with other javascript stuff), you can create a Flash movie that takes input, feeds it to javascript, and then javascript tells it falls back to Flash. Take a look at the documentation here ).

+3


source


Check out ExternalInterface which allows you to call javascript functions from actionscript and vice versa. We use it without problems in my work.



+1


source


The syntax is pretty much the same, but the DOM is missing. Instead, you have object references. This is a little more like what you are doing in something like VB. Variable scope works in different ways.

Instead of showing or hiding DIVS or navigating to pages, you move to a different location in the timeline where different objects are shown or hidden. It takes a bit of effort to wrap your head around you if you're a traditional programmer, but it still looks a lot like JavaScript internally.

You might probably take a lot of your logic and rework it, but the UI hooks should change a bit.

0


source







All Articles