R – Can’t get ExternalInterface in flash to work

actionscriptexternalinterfaceflash

very new to flash. I'm using the XSPF music player (the slim version found here (http://musicplayer.sourceforge.net/), written in AS2) to play through a list of mp3s on a website. I need to make a javascript call each time it loads a track. I'm attempting to do this through ExternalInterface, but so far with no luck. Here's my setup: I'm writing the site on a linux machine which also houses the testing server, but editing the flash in windows. I'm testing the site on the same linux box with firefox 3.0.10. The html and actionscript are posted here(http://pastebin.com/f36b1da0e). Does anyone see anything wrong with my code? Any idea as to why it's not working? I feel like it's something in my basic setup…

Thanks,
Dan

Best Answer

I've had a quick look at your code and it seems OK (actionscript anyway). What I would say is to try different methods of embedding the swf. Ages ago (so I can't remember all the details) but I was testing the external interface with different browsers and sometimes it would work in IE, but not firefox, and if I tried a different method of embedding the swf it would work in firefox but not IE or just IE 6 and not 7!

It was very annoying. Anyway the only method I found that worked in both of the major browers at the time (chrome was out) was to use the HTML that gets created from flexbuilder when you publish your app. I did of course have to modify it a bit (because we use cocoon & xsl's) but it worked.

(since then I think swfobject has been improved, i might try that as well if I was you)

I've posted the HTML template from flexbuilder on http://pastebin.com/f79b5b3f3 It will require the AC_OETags.js file (http://pastebin.com/f3937a336) and the playerProductInstall.swf (you may need to download flexbuilder to get this).


code for comment below

<mx:HTTPService id="mySerivceCall" 
    url="{'myPHPFile.php'}"
    result="resultHandler(event)" 
    fault="faulthandler(event)"
    showBusyCursor="false" 
    resultFormat="e4x"> 
    <mx:request>
        <time>{new Date().getTime()}</time>
    </mx:request>
</mx:HTTPService>

I always add the time to a httpservice, makes sure that it doesn't get cached (which IE is very bad at). Just stick in any other params into the request section and the result format just tells flex that the result is XML formatted in e4x which makes handling XML very straight forward.