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

ExternalInterface.addCallback

Explorer ,
Dec 13, 2011 Dec 13, 2011

when communicating with flash from javascript is there a special setup that is required for flash.

the function in my actionscript (flash) is never called (the trace is never executed).  i have been

searching for examples and help and everything i read looks like this should work.

all i am trying to do is send a text string to flash from javascript.

can anyone help me on this?

thanks

ACTIONSCRIPT 3.0 (code)

i have a flash program with just a dynamic text item named myTxt.

import flash.external.ExternalInterface;

import flash.display.*;

if (ExternalInterface.available) {

  trace("external call okay");

    ExternalInterface.addCallback("sendTextToAS3", receiveTextFromJS);

}

//Set up Javascript to Actioscript

function receiveTextFromJS(t:String):void {

  trace('here');

     myTxt.text = t;

}

HTML - JAVASCRIPT (code)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<script type="text/javascript" src="swfobject.js"></script>

<script type="text/javascript">

// get our flash movie object

        var flashMovie;

        function init() {

           if (document.getElementById) {

             flashMovie = document.getElementById("flashDIV");

           }

        }

 

      // wait for the page to fully load before initializing

       window.onload = init;

function sendTextToAS3(){

alert ('send');

        var Txt = document.getElementById('htmlText').value;

alert ('send ' +Txt);

flash.sendTextFromJS(Txt);

       }

var flashvars = {};

var params = {};

params.allowscriptaccess = "always";

params.swliveconnect = "true";

var attributes = { id: "fvars1", name: "fvars1" };

swfobject.embedSWF("fvars1.swf", "flashDIV", "800", "600", "9.0.0", false, flashvars, params, attributes);

       </script>

</head>

<body>

     <textarea name="htmlText" id="htmlText" cols="50" rows="15"> </textarea><br />

     <input type="button" name="sendToFlash" id="sendToFlash" value="Send Text To Flash" onclick="sendTextToAS3();" />

<div id="flashDIV">

<a href="http://www.adobe.com/go/getflashplayer">

<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />

</a>

</div>

</body>

</html>

TOPICS
ActionScript
1.5K
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
Community Expert ,
Dec 13, 2011 Dec 13, 2011

with addCallBack() yes, there is special javascript that needs to be used.   to be sure:

flash.sendTextFromJS(Txt);

isn't correct.  it's possible

flashMovie.sendTextFromJS(Txt);

might work but i doubt it.   you should check the flash help files for sample code.

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 ,
Dec 13, 2011 Dec 13, 2011

thanks kglad.  i corrected that and it did not fix.

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 ,
Dec 13, 2011 Dec 13, 2011

is my code that far off???

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
Community Expert ,
Dec 13, 2011 Dec 13, 2011

try:

function sendTextToAS3(){

        var Txt = document.getElementById('htmlText').value;

alert ('send ' +Txt);

document.getElementById("fvars1").sendTextFromJS(Txt);

       }

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 ,
Dec 13, 2011 Dec 13, 2011

thanks,  really appreciate your input.

did not work.  must be something i am

doing that is wrong.

this stuff is not straightforward for me

and its hard to find examples that work.

but i do thank you

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
Community Expert ,
Dec 13, 2011 Dec 13, 2011

then try:

function sendTextToAS3(){

        var Txt = document.getElementById('htmlText').value;

alert ('send ' +Txt);

document.getElementById("flashDIV").sendTextFromJS(Txt);

       }

p.s.  actually, assigning two different id's for the same div may be a problem.  use one of the other id values but not two different ones.

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 ,
Dec 14, 2011 Dec 14, 2011

kglad,

thanks for your responses and help.

the code snippets you provided did not work......BUT the

links of where to find some help and examples are

of great use.

thanks for pointing me in the right direction for research.

teremoto

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
Community Expert ,
Dec 14, 2011 Dec 14, 2011
LATEST

you're welcome.

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