How to call dynamically created external Flash interface in IE from javascript?

What I have:

  • SWF exports a function via ExternalInterface
  • Javascript creates a new embed object and adds it to the document
  • Flash calling functions work fine in other browsers
  • Flash function call will not be executed in IE 8

An example of exporting functions in swf:

flash.external.ExternalInterface.addCallback("isActive", ... 

An example of creating an embed object:

 var b = document.createElement('embed'); b.type = 'application\u002fx-shockwave-flash'; b.setAttribute('allowFullScreen', 'true'); b.setAttribute('allowNetworking', 'all'); b.setAttribute('allowScriptAccess', 'always'); b.width = 500; b.height = 400; b.src = 'assets\u002fUltra4.UltraApplication\u002fUltra4.UltraApplication+UltraSprite.swf'; 

An example of invoking the Flash frontend in javascript:

  try { e = b.isActive(); } catch (__exc){ } 

In IE, he will catch the message "Object does not support this property or method"

How to fix it?


In the script debugger, I see a third-party script that should be a bridge:

 function __flash__arrayToXML(obj) { var s = "<array>"; for (var i=0; i<obj.length; i++) { s += "<property id=\"" + i + "\">" + __flash__toXML(obj[i]) + "</property>"; } return s+"</array>"; } function __flash__argumentsToXML(obj,index) { var s = "<arguments>"; for (var i=index; i<obj.length; i++) { s += __flash__toXML(obj[i]); } return s+"</arguments>"; } function __flash__objectToXML(obj) { var s = "<object>"; for (var prop in obj) { s += "<property id=\"" + prop + "\">" + __flash__toXML(obj[prop]) + "</property>"; } return s+"</object>"; } function __flash__escapeXML(s) { return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;"); } function __flash__toXML(value) { var type = typeof(value); if (type == "string") { return "<string>" + __flash__escapeXML(value) + "</string>"; } else if (type == "undefined") { return "<undefined/>"; } else if (type == "number") { return "<number>" + value + "</number>"; } else if (value == null) { return "<null/>"; } else if (type == "boolean") { return value ? "<true/>" : "<false/>"; } else if (value instanceof Date) { return "<date>" + value.getTime() + "</date>"; } else if (value instanceof Array) { return __flash__arrayToXML(value); } else if (type == "object") { return __flash__objectToXML(value); } else { return "<null/>"; //??? } } function __flash__addCallback(instance, name) { instance[name] = function () { return eval(instance.CallFunction("<invoke name=\""+name+"\" returntype=\"javascript\">" + __flash__argumentsToXML(arguments,0) + "</invoke>")); } } function __flash__removeCallback(instance, name) { instance[name] = null; } 
+7
dom internet-explorer flash
source share
3 answers

I am not sure if I understand your question correctly. But I think you are missing a few things:

1) The embed tag requires a name attribute. Name it "NewFlashMovie" for the following code:

 b.name = "NewFlashMovie"; 

2) You can call the isActive function differently using an external function. Add this feature first

  function thisMovie(movieName) { if (navigator.appName.indexOf("Microsoft") != -1) { return window[movieName]; } else { return document[movieName]; } } 

Then you can call a function like this

thisMovie("NewFlashMovie").isActive();

In my experience, this "thisMovie" is necessary to overcome IE-Flash calls. This is also described in the ExternalInterface documentation.

3) I also recommend using swfobject instead of creating your own "embed" object.

Hope this helps.

+3
source share

I found that for IE, when calling Javascript from ActionScript, I need to specify the id attribute for the object tag. IE method of processing ExternalInterface.call (...) - method call for an object . IE issues code

 document.getElementById("...").SetReturnValue(...) 

Without the id attribute of your object tag, this will be reduced to

 document.getElementById("").SetReturnValue(...) 

which is trying to call SetReturnValue for a null object.

Please note that the id attribute is not required for other browsers, but it doesn’t actually hurt.

In your case, something like this may happen: perhaps the "name" attribute in embed may help.

+1
source share

Could this be due to the fact that you are creating an Embed tag instead of an Object tag? IE traditionally uses Object tags to embed Flash content

See Adobe Tech for discussion: http://kb2.adobe.com/cps/415/tn_4150.html

0
source share

All Articles