referencing the html object that made the ExternalInterface.call to the javascript function called

穿精又带淫゛_ 提交于 2019-12-11 06:17:59

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/6504369/referencing-the-html-object-that-made-the-externalinterface-call-to-the-javascri

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