views:

35

answers:

2

Hi.

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: http://stackoverflow.com/questions/1473741/ 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.

A: 

Try $('#player_external').get(0).MyFunc();

Thomas
No. That doesn't help. I think the problem may be because the div element is dynamically created, or because the swfobject doesn't add <embed> tag inside of an object (at least firebug shows it this way).
Skotona
Ohhh! I think your comment just pointed it out. The exposed callback is a method of the object-element in the DOM. EDIT: Prematurely hit Enter. So, you have to make sure that you're operating on the *object-element* with your jQuery selector, and not on the div-element that SwfObject replaces.
Thomas
I've tried many different ways to get object element, and i'm sure that i'm getting object element, not the div. But the function doesn't work.
Skotona
A: 

Hi, This: $('#myContent').get(0).method() totally works for me. Using array reference to get the first item also works: $('#myContent')[0].method()

I'm using the 'dynamic' swfobject injection.

Misha Rabinovich