Hi, Finally I've tracked it down: registering JS callbacks in Flash does not work when the diff to which the object is added is not
given this as file: == Main.as == package { import flash.display.*; import flash.external.*; public class Main extends Sprite { public function Main ():void { trace("start"); ExternalInterface.addCallback("backgroundImage", backgroundImage); } static public function backgroundImage(s:String):void{ trace("got image in Test.as "+ s); } } } == which you can compile easily eg using mxmlc. You should get Main.swf Given this HTML document: <html> <head> <script type="text/javascript" src="js/mootools-1.2.4-core-nc.js"></script> </head> <body> <!-- TESTCASE 1 --!> <div id="div_works"></div> <a href="#" onclick="$('works').backgroundImage('dummy string')">works</a> <hr/> <!-- TESTCASE 1 --!> <div id="div_worksnot"></div> <a href="#" onclick="$('worksnot').backgroundImage('dummy string')">works not</a> <script type="text/javascript" charset="utf-8"> window.addEvent("domready", function(){ // SCRIPT TESTCASE 1 // callback works var s = new Swiff("Main.swf", {'id': 'works', 'container': 'div_works' ,'height': '100px', 'width': '300px'}); // SCRIPT TESTCASE 2) // callback works not - but Flash object is displayed var s = new Swiff("Main.swf", {'id': 'worksnot', 'height': '100px', 'width': '300px'}); $("div_worksnot").adopt(s.toElement()); }); </script> </body> </html> you notice that everything is fine opening the document in Firefox (You may have to set security settings or use Apache). However when you open the same document in IE both swf elemnts are displayed correctly but only the first one will have an exposed backgroundImage JS function. So only the first link will trace a message. This missbehaviour should be documented. I took me sevaral hours to track it down because it was the first time that I was calling into Flash. I don't think there is a fix because I've tried both: a) adding the tmp div created to the document before setting html to build. result: works. If you inject the object element somewhere else callbacks are gone. this.object = ((container) ? container.empty() : new Element('div')).set('html', build).firstChild; b) additg tmp div to document after html was set to build. result: doesn't work at all. Conclusion: IE is buggy (?). I can't find a workaround. So it's best to document this bug. == I'd like to take action == I'd like to improve the Mootools documentation. However I can't yet because I need a working example for a flash CallFunction implementation. Swiff.remote = function(obj, fn){ var rs = obj.CallFunction('<invoke name="' + fn + '" returntype="javascript">' + __flash__argumentsToXML(arguments, 2) + '</invoke>'); return eval(rs); }; __flash__argumentsToXML is defined whenever a flash element finishes loading. Is it the task of the programmer to define CallFunction ? Does someone have a working implementation? Why does the Mootools documentation give this example: var obj = new Swiff('myMovie.swf'); //Alerts "This is from the .swf file!". alert(Swiff.remote(obj, 'myFlashFn')); Isn't Mootools about OO? So shouldn't this be obj.remote('myFlashFn' [, args]) ? Why doesn't the documentation tell me that I can use obj.myFlashFn(..) equally well? (Maybe I can't because of the __flash__argumentsToXML function) So two things should be done: a) document missbehaviour of IE b) give an example how to implement CallFunction (?) Have I missed something? Marc Weber To unsubscribe from this group, send email to mootools-users+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.