Hey Guys,
I've got ExternalInterface to call a javascript function. But how can I now use jQuery to target the .swf that called the function?
For example, I'm calling the "changeObject" function using ExternalInterface. How would I get jQuery to modify the same flash files object tag? This is what I have and it doesn't work:
function changeObject()
{
jQuery(this).css('height','500px');
};
jQuery(this) get's returned as undefined. I do not know the ID of the object element. It's a dynamic ID. There will be multiple .swf's on a page too.
Thanks!
So I set a new Flashvar that was a unique playerID. Like this:
var flashvars = {};
flashvars.src = '<?= $this->get('link') ?>';
flashvars.playerID = '<?= "flash-".uniqid(); ?>';
var params = {};
params.allowscriptaccess = 'always';
var attributes = {};
attributes.id = '<?= $this->get('attributeId') ?>';
swfobject.embedSWF('<?= $this->get('pluginUrl') ?>/flash/wiredrivePlayer.swf', 'no-flash-content', '100%', '100%', '10.0.0', 'expressInstall.swf', flashvars, params,attributes);
I then setup that Flashvar in actionscript (in Model.as):
// Add into the "Declare private vars" section
private var _playerID:String;
// Add into the private function init(flashvars:Object) section
_playerID = flashvars.playerID;
//Add into the public functions section
public function get playerID():String {
return _playerID;
}
//Add into the public function endOfItem() section
// inform JavaScript that the FLV has stopped playing
ExternalInterface.call("stoppedPlaying", _playerID);
Then in Javascript I now have the playerID to use like this:
function stoppedPlaying(playerID)
{
// do something when the FLV starts playing
var playerID = '#' + playerID
jQuery(playerID).css('background','red');
}
So I just use the arg playerID instead of the (this) in jQuery. So happy!
I don't think there's any way to get the caller object, but one solution would be to add an attribute to that changeObject function and pass the id of the swf to that from your Flash app.
I had a quick look through the documentation and this doesn't appear to be possible (but I'm quite possibly wrong, and invite anyone with more knowledge on the subject to correct me).
What you can try to do is initiate each swf with an identifier, and then pass that identifier back with every function call (the identifier would match the swf object's ID).