2010-11-15 79 views
2

嘿伙计, 我有ExternalInterface来调用一个javascript函数。但是,我现在如何使用jQuery来定位调用该函数的.swf?jQuery(this)and ExternalInterface

例如,我使用ExternalInterface调用“changeObject”函数。我将如何让jQuery修改相同的Flash文件对象标签?这是我有,它不工作:

function changeObject() 
{ 
    jQuery(this).css('height','500px'); 
}; 

jQuery(this)get的返回为undefined。我不知道对象元素的ID。这是一个动态ID。页面上也会有多个.swf文件。

谢谢!

回答

1

所以我设置了一个新的Flashvar,它是一个独特的playerID。就像这样:

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

然后我设置的是Flash变数的动作(在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);  

然后在Javascript我现在playerID像这样使用:

function stoppedPlaying(playerID) 
    { 
     // do something when the FLV starts playing 
     var playerID = '#' + playerID 
     jQuery(playerID).css('background','red'); 

    } 

所以我只使用arg playerID而不是jQuery中的(this)。很高兴!

0

我不认为有任何方法来获取调用者对象,但一种解决方案是将一个属性添加到该changeObject函数并将swf的id传递给您的Flash应用程序。

0

我对文档进行了快速浏览,并且这看起来不太可能(但我很可能是错误的,并邀请任何对此主题有更多了解的人来纠正我)。

你可以尝试做的是用标识符初始化每个swf,然后在每次函数调用时将该标识符返回(标识符将匹配swf对象的ID)。

+0

那么如何让ExternalInterface将对象的ID发送给JS函数呢?我正在使用swfObject动态地嵌入SWF。所以我认为这将与attributes.id设置有关。 – 2010-11-15 22:49:12

+0

我试图找出它可能:http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html#objectID – 2010-11-16 00:11:26