简体   繁体   English

从Flash定位特定的JavaScript对象实例

[英]Targeting specific JavaScript object instance from flash

Greetings, first time poster. 问候,第一次海报。
Let's say a have flash(swf) object on my page, and I have a specific JavaScript class (lets call it "JSClass")that works with that flash object. 假设我的页面上有一个flash(swf)对象,并且我有一个与该Flash对象一起使用的特定JavaScript类(称为“ JSClass”)。 JavaScript class has some methods for communicating with the flash object. JavaScript类具有一些用于与Flash对象通信的方法。 When the flash object is embedded in to page via swfObject , I create an instance of the JSClass , and give it the id of the flash object on the page , so that instance can specifically communicate with that flash object. 当Flash对象通过swfObject嵌入到页面中时,我将创建JSClass的实例,并在页面上为其指定Flash对象的ID,以便该实例可以与该Flash对象进行特定的通信。 I have more than one same flash file on the page, and I need to differentiate calls to specific flash objects. 页面上有多个同一个Flash文件,我需要区分对特定Flash对象的调用。
Something like this: 像这样:

var flashControl1 = new JSClass('flash_id_1');
var flashControl2 = new JSClass('flash_id_2');

// so later I can start the first flash object
flashControl1.startAnimation();

// and stop animation on the second flash object
flashControl2.stopAnimation();

That all works fine. 一切正常。 The problem that I'm having is that, flash objects need to do some stuff internally before they can be manipulated via JavaScript ( they need to load in some stuff etc...) 我遇到的问题是,Flash对象需要先在内部做一些事情,然后才能通过JavaScript进行操作(它们需要加载一些东西,等等...)

Flash objects need to notify the instances of the JSClass that are referencing them, that they are ready to be manipulated. Flash对象需要通知引用它们的JSClass实例,可以对其进行操作。 something like this. 这样的事情。

flashControl1.onFlashReady = function()  
{  
// do some stuff here when the flash is ready.  
}

How can I call "flashControl1.onFlashReady()" from flash? 如何从Flash调用“ flashControl1.onFlashReady()”? Note that flash doesn't know which JSCLass instance to target. 请注意,flash不知道要定位到哪个JSCLass实例。 How can target particular JSClass instances from flash object. 如何从Flash对象中定位特定的JSClass实例。

I suggest you pass the flash_id via flashvars to your flash movies and when a flash movies' initailization is done you use ExternalInterface.call("someJsMethod", flashId); 我建议您通过flash_idflash_id传递给Flash电影,并在完成Flash电影的初始化后,使用ExternalInterface.call("someJsMethod", flashId); to notify your javascript. 通知您的JavaScript。 In your javascript method someJsMethod(flashId) you can then check the id and map it to your JSClass. 然后,在您的javascript方法someJsMethod(flashId)您可以检查ID并将其映射到您的JSClass。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM