Skip to main content
nandinidas
Known Participant
September 14, 2015
Answered

Is there a way to call actionscript from Javascript ?

  • September 14, 2015
  • 3 replies
  • 1924 views

Is there a way to call actionscript from Javascript without using External Interface. The call is from Javascript to Flash actonscript.

Regards,

This topic has been closed for replies.
Correct answer robdillon

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;

}


Yes. If you call a Javascript function that doesn't exist, you will get an error.

3 replies

robdillon
Participating Frequently
September 18, 2015

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-actionscript-callbac… It shows the process of creating the AS function, adding the callback to Javascript and then the Javascript call to the Flash function.

nandinidas
Known Participant
September 20, 2015

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;

nandinidas
Known Participant
September 20, 2015

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;

}

Participating Frequently
September 14, 2015

What's your conditions that make External Interface inappropriate?

nandinidas
Known Participant
September 15, 2015

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,

robdillon
Participating Frequently
September 15, 2015

While two way communication is possible, it's not necessary. You can use ExternalInterface for your need.

robdillon
Participating Frequently
September 14, 2015

Not that I know of.