引用对 javascript 函数进行ExternalInterface.call 的 html 对象

发布于 2024-11-17 17:53:30 字数 854 浏览 2 评论 0 原文

如果我的术语有问题,我深表歉意,我的动作脚本技能非常薄弱。

所以,我有一些动作脚本可以创建一个

ExternalInterface.call('someFunction');

称呼。

是否可以使用ExternalInterface.call调用直接引用对someFunction进行调用的html对象?

假设进行调用的对象也有一些可通过 javascript 访问的回调(通过ExternalInterface.addCallback)。

目前:

Actionscript source

ExternalInterface.call("someFunction");
ExternalInterface.addCallback("someCallback",someASfunction);

Javascript source

function someFunction(){
    document.getElementById('idOfSWFObject').someCallback();
}

我认为必须有一种方法:

Actionscript source

ExternalInterface.call("someFunction",THE_OBJECT_MAKING_THE_CALL);
ExternalInterface.addCallback("someCallback",someASfunction);

Javascript source

function someFunction(o){
    o.someCallback();
}

再次对术语感到抱歉。尝试在其中添加尽可能多的关键字以供将来搜索。

谢谢!

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

call.

is it possible to reference the html object that made the call to someFunction directly using the ExternalInterface.call call?

Assume that the object that makes the call also has some Callbacks (via ExternalInterface.addCallback) that are accessible via javascript.

Currently:

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.

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

π浅易 2024-11-24 17:53:30

我猜你正在谈论ExternalInterface.objectID。此属性返回与 objectembed 标记中的 Flash 容器关联的 ID。

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方法。这样就不需要在 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"]();
}

编辑:如果您确实想在 someFunction 参数中获取对 flash DOM 对象的引用,您可能会以一种有点棘手的方式实现它(我宁愿不这样做,但只是为了您的兴趣)。

// 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 代码从 flash 注入到 js 中。它有效,但看起来很混乱。

I guess you are talking about ExternalInterface.objectID. This property returns an id associated with flash container in object or embed tag.

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

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.

Here's an example

// 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"]();
}

EDIT: 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]();
}

This way you inject some JS code from flash into js. It works, but looks messy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文