views:

143

answers:

3

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

+3  A: 

Well, ActionScript 1 is essentially javascript, and 2 is just some syntactical sugar on top of it. If you're creating a Flash 8 or earlier movie then you should be able to use the javascript code without much tweaking (preferably switching to use classes instead of prototype). Moving it to ActionScript 3 (for Flash 9 or later) would be a little more work as it's more strict about types and such, but still probably not too difficult.

As others have mentioned, the UI-related stuff is quite different in Flash than Javascript, as there is no DOM. I assumed the methods you were talking about are for doing calculations and not really related to the UI at all. If your javascript methods are actually doing UI stuff then moving them to Flash would be much more involved.

Another possibility, if you want to keep your code in javascript (perhaps so you can reuse it with other javascript stuff) then you could create a Flash movie that takes the input, passes it to javascript, and then have javascript report the results back to Flash. Take a look at the Flash ExternalInterface documentation (see also here).

Herms
A: 

The syntax is much the same, but there is no DOM. You have object references instead. It's a bit more like you do in something like VB. Variable scoping works differently too.

Instead of showing or hiding DIVS, or going to pages, you're moving to a different place in the timeline where different objects are shown or hidden. It take a bit of effort to wrap your head around it if you're a traditional programmer, but it still feels very much like JavaScript on the inside.

You can probably take a lot of your logic and recycle it, but the UI hooks will need to change a bit.

Diodeus
+1  A: 

Check out ExternalInterface, which lets you call javascript functions from actionscript, and vice versa. We use it without a problem at my work.

llimllib