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

Dynamically embedded swf with externalInterface calling

Guest
Apr 08, 2012 Apr 08, 2012

Copy link to clipboard

Copied

Hi all,

I have a swf doing some javascript calls. It works fine if the swf object is embeded as part of html. When creating it thru javascript, the code doesn't work. I've tried back &forth for a while, no luck. attached my code snippet below, can someone give me an idea on what might work?

TIA -s

/* javascript */

<script language="javascript">
var g31=false,g32=false,g33=-1,g1=-1;
function f31(p){
   alert(p)
}

function f34()
{
g31=true;
g33>=0&&(window.clearTimeout(g33),g33=-1);
//alert("f34:g31="+g31+";g32="+g32);
if(g32){
     var a=f37();
  a&&(a.f34())
    return
}
g33=window.setTimeout(f34, 100);
}
  function f35()
{
// alert("f35:g31="+g31+";g32="+g32);
  g32=!0;
}
function f36()
{
//  alert("f36:g31="+g31+";g32="+g32);
  return g31;
}
function f37()
{
    if (navigator.appName.indexOf("Microsoft") != -1) 
         return window["testswf"];
       else
        return document["testswf"];
}
(function(){
     var f0=function(){
       g31=true;
       f34();
     };
    
   var f00=function(){
    g1&&(window.clearTimeout(g1),g1=-1);
    if(!document.body)
    {
     g1=window.setTimeout(f00, 100);
     return
    }
       var swf="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'";
      swf+="codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0'";
      swf+="width='215' height='318' id='testswf' align='middle'>";
      swf+="<param name='allowScriptAccess' value='always' />";
            swf+="<param name='allowFullScreen' value='false' />";
            swf+="<param name='movie' value='testswf.swf' />";
               swf+="<param name='quality' value='high' />";
               swf+="<param name='wmode' value='transparent' />";
               swf+="<embed src='testswf.swf' quality='high' wmode='transparent' width='215' height='318' name='testswf' align='middle' allowScriptAccess='always' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' /></object>";
     var a=document.createElement("div");
      a.innerHTML=swf;
      f0();
   };
    f00();
  })();
</script>

/*as3 */

import flash.external.ExternalInterface;

flash.system.Security.allowDomain("*");

startTest();

function f0():void {
ExternalInterface.call("f31", "one");
}
function timerHandler(event:TimerEvent):void
{
    if (isContainerReady())
    {
         Timer(event.target).stop();
         setupCallbacks();
    }
}
function startTest():void
{
   if (ExternalInterface.available)
    {
        try
        {
            if (isContainerReady())
            {
               setupCallbacks();
            }
            else
            {
                var readyTimer:Timer = new Timer(100);
                readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
                readyTimer.start();
            }
        }
        catch(error:Error) {
   trace("An Error occurred: " + error.message + "\n");
  }
    }
    else
    {
        trace("External interface is not available for this container.");
    }

}
function isContainerReady():Boolean
{
    var result:Boolean = ExternalInterface.call("f36");
    return result;
}

function setupCallbacks():void
{
    ExternalInterface.addCallback("f34", f0);
    ExternalInterface.call("f35");
}

TOPICS
ActionScript

Views

568

Translate

Translate

Report

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
Guest
Apr 08, 2012 Apr 08, 2012

Copy link to clipboard

Copied

LATEST

added document.body.appendChild(a); added space at the beginning of each line of swf object.

still not working

Votes

Translate

Translate

Report

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