jQuery(this) and ExternalInterface

强颜欢笑 提交于 2019-12-01 11:59:53

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!