引用,使得该ExternalInterface.call来调用的JavaScript函数的HTML对象 [英] referencing the html object that made the ExternalInterface.call to the javascript function called
问题描述
我道歉,如果我的术语是关闭的,我的动作技能是pretty的弱酱。
i apologize if my terminology is off, my actionscript skills are pretty weak sauce.
所以,我有一些动作,使一个
so, i have some actionscript that makes a
ExternalInterface.call('someFunction');
ExternalInterface.call('someFunction');
电话。
是否有可能引用,使得调用someFunction的HTML对象直接使用ExternalInterface.call调用?
is it possible to reference the html object that made the call to someFunction directly using the ExternalInterface.call call?
假设,使得调用也物体有一定的回调(通过ExternalInterface.addCallback)是通过JavaScript访问。
Assume that the object that makes the call also has some Callbacks (via ExternalInterface.addCallback) that are accessible via javascript.
目前:
Actionscript source
ExternalInterface.call("someFunction");
ExternalInterface.addCallback("someCallback",someASfunction);
Javascript source
function someFunction(){
document.getElementById('idOfSWFObject').someCallback();
}
我想必须有一个方法:
I'm thinking there must be a way of:
Actionscript source
ExternalInterface.call("someFunction",THE_OBJECT_MAKING_THE_CALL);
ExternalInterface.addCallback("someCallback",someASfunction);
Javascript source
function someFunction(o){
o.someCallback();
}
再次,遗憾的术语。试图用尽可能多的关键字搜索的未来蕾丝吧。
once again, sorry about the terminology. tried to lace it with as many keywords for future searches.
谢谢!
推荐答案
我猜你是在谈论ExternalInterface.objectID。该属性返回Flash容器相关的ID中的对象或嵌入的标签。
I guess you are talking about ExternalInterface.objectID. This property returns an id associated with flash container in object or embed tag.
<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html?filter_flex=4.1&filter_flashplayer=10.2&filter_air=2.en#objectID" rel="nofollow">http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html?filter_flex=4.1&filter_flashplayer=10.2&filter_air=2.en#objectID
我建议你也应该通过someCallback给你的JS方法的名称。这样,就没有必要到c很难$ C $的JS。
I suggest that you should also pass the name of "someCallback" to you JS method. This way there will be no need to hardcode it in JS.
下面是一个例子
// Actionscript source
const jsMethodName:String = "someFunction";
const asCallbackName:String = "someCallback";
ExternalInterface.call(jsMethodName+"(document.getElementById("++")"++");");
ExternalInterface.addCallback(asCallbackName,someASfunction);
// Javascript source
function someFunction(flashId, callbackName)
{
var flashContainer = document.getElementById(flashId);
flashContainer["callbackName"]();
}
编辑:如果您真的想获得一个对Flash DOM对象someFunction参数,可以实现在一个有点棘手的方式(我宁愿没有,但只是为你的兴趣)。
If you really want to get a reference to flash DOM object in someFunction arguments, you may achieve it in a bit tricky way (I would rather not, but just for your interest).
// Actionscript source
const jsMethodName:String = "someFunction";
const asCallbackName:String = "someCallback";
ExternalInterface.addCallback(asCallbackName,someASfunction);
ExternalInterface.call(
"function(){"+
jsMethodName+"("+
"document.getElementById('"+ExternalInterface.objectID+"'),"+
"'"+asCallbackName+"'"+
");"+
"}"
);
// Javascript source
function someFunction(flashContainer, callbackName)
{
flashContainer[callbackName]();
}
这样你注入从闪存一些JS code到JS。它的工作原理,但看起来凌乱。
This way you inject some JS code from flash into js. It works, but looks messy.
这篇关于引用,使得该ExternalInterface.call来调用的JavaScript函数的HTML对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!