Reputation: 11
I'm trying to write a simple flash mp3 player while using JQuery and it's SWF Object plugin. I'm adding an swf to the page using this code:
$("body").append("<div id='player_external' style='position:absolute;top:0;left:0;height:1px;width:1px;'></div>");
$('#player_external').flash({swf:"player_external.swf",wmode:"transparent",height:1,width:1,AllowScriptAccess:"always"});
The player should be invisible one-pixel object that interacts with javascript.
When i'm calling javascript functions from within flash objects (using ExternalInterface.call()
) it works fine.
But when i try to call ActionScript function from JavaScript nothing happens. I have added a callback function like this:
ExternalInterface.addCallback("MyFunc",MyFunc);
And I've tried all possible ways I've found on the internet. Like:
$('#player_external').context.MyFunc();
$('#player_external').flash("MyFunc()"); //this just crashes browser!
Also, the solution found here: How can I call an Actionscript function when the .swf is referenced by jQuery? doesn't help. I gave up my hope on this. Maybe it's better to use flash without JQuery's help. But there just should be some way to do this.
Thanks.
Upvotes: 1
Views: 3067
Reputation: 1679
Using $('#myContent').get(0).method()
works for me. Using array reference to get the first item also works: $('#myContent')[0].method()
I'm using 'dynamic' swfobject injection.
Upvotes: 0
Reputation: 21
Just append an id paramter, so you can access the Flash object directly:
$('#my_container').flash({
swf: 'swf/test.swf',
width: 740,
height: 110,
wmode: 'transparent',
allowScriptAccess:'always',
id:'my_flash',
flashvars: {}
});
// Use document.getElementById NOT $("#my_flash")
document.getElementById("my_flash").myInternalFlashFuctionName('Foo');
Upvotes: 2