Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Is there a way to call actionscript from Javascript ?

Explorer ,
Sep 14, 2015 Sep 14, 2015

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

Regards,

TOPICS
ActionScript
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 20, 2015 Sep 20, 2015

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

Translate
LEGEND ,
Sep 14, 2015 Sep 14, 2015

Not that I know of.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 14, 2015 Sep 14, 2015

What's your conditions that make External Interface inappropriate?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 14, 2015 Sep 14, 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,

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 15, 2015 Sep 15, 2015

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 15, 2015 Sep 15, 2015

Can you please help me with the code to communicate from Javascript to actionscript ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 16, 2015 Sep 16, 2015
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 18, 2015 Sep 18, 2015

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 ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 18, 2015 Sep 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-... It shows the process of creating the AS function, adding the callback to Javascript and then the Javascript call to the Flash function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 19, 2015 Sep 19, 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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 20, 2015 Sep 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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 20, 2015 Sep 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;

return javascriptObject;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2015 Sep 20, 2015

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 20, 2015 Sep 20, 2015

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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2015 Sep 20, 2015

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 21, 2015 Sep 21, 2015
LATEST

ok..Thanks..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines