Copy link to clipboard
Copied
Is there a way to call actionscript from Javascript without using External Interface. The call is from Javascript to Flash actonscript.
Regards,
1 Correct answer
Yes. If you call a Javascript function that doesn't exist, you will get an error.
Copy link to clipboard
Copied
Not that I know of.
Copy link to clipboard
Copied
What's your conditions that make External Interface inappropriate?
Copy link to clipboard
Copied
As far as I know External Interface is for 2 way communication i.e. from Actionscrip to Javascript and from Javascript to Actionscript. I want only one way communication i.e from Javascript to Actionscript.
Regards,
Copy link to clipboard
Copied
While two way communication is possible, it's not necessary. You can use ExternalInterface for your need.
Copy link to clipboard
Copied
Can you please help me with the code to communicate from Javascript to actionscript ?
Copy link to clipboard
Copied
Here's a good example here:https://circlecube.com/says/2010/12/actionscript-as3-javascript-call-flash-to-and-from-javascript/
Copy link to clipboard
Copied
Ok so can we use the ExternalInterface.addcallback("name_of_js_function", "name of as function") without using the ExternalInterface.call("name_of_js_function", "data passed to js") function ?
Copy link to clipboard
Copied
Yes. That second line is used to call a Javascript function and pass a string to the function. I thought that you wanted to call an Actionscript function in your Flash movie from Javascript?
Have a look at the last answer in this link: http://stackoverflow.com/questions/18298049/externalinterface-call-works-but-javascript-cant-access-... It shows the process of creating the AS function, adding the callback to Javascript and then the Javascript call to the Flash function.
Copy link to clipboard
Copied
When I am trying to call the actioscript function from javascript by using the addCallback method given below I am getting an error message: Access to possibly undefined property getcontentid. Dont know why. I have imported the ExternalInterface package in my as file and have a getcontentid method defined in the file.
ExternalInterface.addCallback("ASContentIdFunction", getcontentid);
public function getcontentid():String{
var nextContent:Object = Object(CarouselItem(CarouselBar.wrapperChildren.getChildAt(Globals.currentRelatedIndex)).data);
var ContentId_id:String=nextContent.contentId;
return ContentId_id;
Copy link to clipboard
Copied
I want to pass a value from Flash movie to a javascript in Html page. Can I use the ExternalInterface,call() method like:
ExternalInterface.call("myJavascriptFunction", Object.contentid, Object.contentType);
or
ExternalInterface.call("myJavascriptFunction", Object);
where the javascript function is like:
function myJavascriptFunction(number1:Number, string1:String){
var contentId=number1;
var contentType=string1;
return contentId;
}
function myJavascriptFunction(Object:Object){
var javascriptObject:Object=Object;
}
Copy link to clipboard
Copied
I want to pass a value from Flash movie to a javascript in Html page. Can I use the ExternalInterface,call() method like:
ExternalInterface.call("myJavascriptFunction", Object.contentid, Object.contentType);
or
ExternalInterface.call("myJavascriptFunction", Object);
where the javascript function is like:
function myJavascriptFunction(number1:Number, string1:String){
var contentId=number1;
var contentType=string1;
return contentId;
}
function myJavascriptFunction(Object:Object){
var javascriptObject:Object=Object;
return javascriptObject;
}
Copy link to clipboard
Copied
There could be a couple of reasons why you're getting this error. Have a look at the example code at the bottom of this Actionscript citation: ExternalInterface - Adobe ActionScript® 3 (AS3 ) API Reference
You'll see that it tests to see if ExternalInterface is available and that Javascript is ready. These are both good practice when testing.
Your .as file that contains the code listed above may not be properly connected to and called from the Flash file. I can't really tell from the code that you show. If getContentID() is called from a different .as file then this .as file may not be available when the function is called.
Copy link to clipboard
Copied
Hi,
I have created the getContentId() function in an as file and wanted to call this function from javascript using the ASContentIdFunction. I wanted to access the return string i.e ContentId_id of this function from javascript. The swf is embedded in an html page. I am yet to write the javascript part of the code. Is the error coming because have not written the javascript to call this function ?
ExternalInterface.addCallback("ASContentIdFunction", getcontentid);
public function getcontentid():String{
var nextContent:Object = Object(CarouselItem(CarouselBar.wrapperChildren.getChildAt(Globals.currentRelatedIndex)). data);
var ContentId_id:String=nextContent.contentId;
return ContentId_id;
}
Copy link to clipboard
Copied
Yes. If you call a Javascript function that doesn't exist, you will get an error.
Copy link to clipboard
Copied
ok..Thanks..

