forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcallJSFunction.as
More file actions
40 lines (35 loc) · 1.28 KB
/
callJSFunction.as
File metadata and controls
40 lines (35 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package utils.js {
import flash.external.ExternalInterface;
/**
* Call a JS function.
* @param func Name of the function to be called
* @param arg1 Argument 1
* @param arg2 Argument 2
* @param arg3 Argument 3
* @param arg4 Argument 4
* @throws Error if empty function name supplied
* @throws Error if SecurityError occurred
* @throws Error if Error occurred
* @author Vaclav Vancura (<a href="http://vancura.org">vancura.org</a>, <a href="http://twitter.com/vancura">@vancura</a>)
*/
public function callJSFunction(func:String, arg1:* = null, arg2:* = null, arg3:* = null, arg4:* = null):void {
if(func == "") {
throw new Error("A valid function argument must be supplied");
}
// track avea if a type is supplied
if(ExternalInterface.available) {
try {
ExternalInterface.call(func, arg1, arg2, arg3, arg4);
}
catch(error:SecurityError) {
throw new Error(func + " request failed. A SecurityError occurred: " + error.message + "\n");
}
catch (error:Error) {
throw new Error(func + " request failed. An Error occurred: " + error.message + "\n");
}
}
else {
throw new Error(func + " request Failed. External interface is not available for this container. If you're trying to use it locally, try using it through an HTTP address.");
}
}
}