views:

671

answers:

1

Hello all, 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

A: 

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.

kenneth
forgot to say that you can always use getURL (this was used before externalInterface, in AS2 I'd have used getURL, then when I moved to AS3 I did externalInterface).something like getURL{"Javascript:alert('hello world')"};Be careful with this, if you call 2 getURLs in the same frame then only the last one will actually get called.
kenneth
could I use getURL to call and pass variables to a php function? I'm using ExternalInterface to call javascript to edit an xml file each time a song is played, so it might be better to go through php anyway. Also, I kind of feel like getURL is outdated and may eventually be depreciated; that's been the reason I've stayed away from it so far...
danwoods
as long as you're using AS2, then I see no reason no to use getURL.If you are wishing to call a php file (if you are able to use flex) then you should try an httpservice call (I've pasted code above in answer). passing vars using getURL should be somethign like the following, getURL("myFuncInJavascript(" + param1 + "," + param2 +")");
kenneth
hmm been so long since I looked at AS2, I think e4x may be an AS3 feature?
kenneth
Thanks Kenneth, I'm starting to think I should just scrap the mp3 player I'm using and find one written in as3. Seems like it might solve a lot of headaches...
danwoods
Well I've been using AS3 for ages now and its soooo much better than AS2. You could probably write you're own in a few days (once you get the hang of AS3 and depending on how much functionailty you give it) if you know your way around AS2 already.
kenneth