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

AS3.0 External Interface: Pass variables to flash using javascript

New Here ,
Sep 05, 2010 Sep 05, 2010

Hello all,

I am looking for a simple and straightfoward example of how I can pass the value of a variable into flash using javascript.

Specifically, I'd like to use javascript to pass the filename of an external video file that I would like to load into my flash movie.

I'd also like to call a function in the SWF that plays the movie once the filename as been passed to the flash movie.

External Inferface looks like the way to go.

I've found a few decent AS2.0 examples, but converting them to AS3.0 has proven difficult and many of the examples are much too complex for what I am trying to do.

If you have any code samples or tutorials showing the HTML/Javascript and the associated actionscript I'd really appreciate it!

Thanks!

Tim

TOPICS
ActionScript
4.0K
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 ,
Sep 06, 2010 Sep 06, 2010

if you create a swf (eiTest.swf) and html:

<!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>eiTest</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script language="JavaScript">

         function thisMovie(movieName) {
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
     }
     function f1(value) {
         thisMovie("eiTest").jsF(value);
     }
   
</script>
    </head>
         <body onload="f1('yourfilename.ext');">
     <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
             id="eiTest" width="550" height="400"
             codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
         <param name="movie" value="eiTest.swf" />
         <param name="quality" value="high" />
         <param name="bgcolor" value="#869ca7" />
         <param name="allowScriptAccess" value="sameDomain" />
         <embed src="eiTest.swf" quality="high" bgcolor="#869ca7"
             width="550" height="400" name="eiTest" align="middle"
             play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
             type="application/x-shockwave-flash"
             pluginspage="http://www.macromedia.com/go/getflashplayer">
         </embed>
     </object>
    
    </body>
</html>

you can use:

import flash.external.ExternalInterface;
ExternalInterface.addCallback("jsF", asF);

function asF(fileS:String):void{
trace(fileS);
}

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
New Here ,
Sep 07, 2010 Sep 07, 2010

Thank you kglad! With a little tweaking we got external interface working for us. Thank you for your helpful and timely response!

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 ,
Sep 07, 2010 Sep 07, 2010

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
New Here ,
Dec 23, 2011 Dec 23, 2011
LATEST

Hello Sir,

Nice tutorials.

but did not wwork in Chrome...

Please help soon as possible.

-G

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