1

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.

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

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).
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.
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.
2

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');

1 Comment

I happened to find and read your answer. It solved my problem.Thank you very much.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.