1

Is there any way to call Js function in a .js file from action script file (Here, I mean a "stand alone" .js file, not a js file embedded in html tag)

Suppose I have a file lib.js, and inside it, I have two function hello(str) and bye(str).

Now, I want my function sayHello(str) in my Calculator.as class be able to do something like that:

function sayHello(str:String) : void {
    hello(str)
    ...........
    ...........
    bye(str)
} 

It's possible to have such function like that ?

3 Answers 3

1

You can use ExternalInterface.call to call javascript functions.

Sign up to request clarification or add additional context in comments.

3 Comments

But It must be located inside a Html tag, isn't it ? stackoverflow.com/questions/1674402/…
The javascript code has to be in your html page inside a script tag, or included from an external js file, again with a script tag. <script type="text/javascript"> js code here </script>
Is there any way to use it without Html tag, I mean call a function from .js file from .as file ? I want to do that because I have a lib written in .js file.
1

If the JS file is loaded into the site with the flash, you can use ExternalInterface.call("hello", str) to call it.

3 Comments

Here, I don't use flash, but air. In fact, I have a .as file, I also have a .js library written before. Now, I don't want to rewrite my lib in as3, but directly use it.
Not that I know. There is no JS-interpreter built into the flash runtime. It might be possible to load a HTML page into the Air app, and connect through that (through some native browser), but I think it'll be easier to simply convert the JS code to AS3...
You mean that I will create a HTLM file, then, have something like that <script type="text/javascript" src="abc.js"> </script>. Finally, Load this HTML file with action script 3. At that time, I will be able to use js function, isn't it ?
0

you could try with this one http://livedocs.adobe.com/flex/3/html/help.html?content=ProgrammingHTMLAndJavaScript_02.html

2 Comments

Can you specify it a little more ?
It is a class/component which can load html content. In theory you can put your javascript there and try if it will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.