Flash AS2.0 and JavaScript/jQuery (ExternalInterface) Communication
Posted
by abysslogic
on Stack Overflow
See other posts from Stack Overflow
or by abysslogic
Published on 2010-01-07T08:21:35Z
Indexed on
2010/05/01
8:27 UTC
Read the original article
Hit count: 430
Hi there,
Im trying to use JS to send data to my Flash AS2.0 music player with ExternalInterface, except there are no good tutorials or guides on ExternalInterface that I can find. I want to be able to change the current song in the player by clicking a JavaScript link, and on page / window load without clicking, play a default song.
I dont need a super complicated answer on loading sounds in flash, etc., I am just having a lot of difficulties getting JS to send anything to Flash, and when I get that to work - would I need to put some if / else into the flash to determine if the link has been clicked or not?
Thanks
edit heres the code as of now:
AS 2.0
import flash.external.ExternalInterface;
ExternalInterface.addCallback('loadSong', null, flashFunction);
function flashFunction (val) {
extra = val;
}
JavaScript
var flashObj = document.getElementById('VSPLAYER');
function loadSong(val) {
return val
}
HTML
<a href="javascript:loadSong('2')">Play song 2</a>
<object id="VSPLAYER" type="application/x-shockwave-flash" data="vs_player.swf" width="280" height="90">
<param name="movie" value="vs_player.swf" />
<param name="allowscriptaccess" value="always" />
</object>
© Stack Overflow or respective owner