从 actionscript 调用 javascript 函数

发布于 2024-08-08 21:36:25 字数 268 浏览 3 评论 0原文

我正在尝试从actionscript 调用javascript 函数。

截至目前,我正在使用“ExternalInterface”并且可以取得部分成功。

我可以调用函数(无需任何范围解析),例如“scanDNA()”,该函数对所有人都可见。但我无法像这样调用函数(指定范围) “真核动物.脊索动物.脊椎动物.颌口目.四足动物.哺乳动物.scanDNA()”。

请让我知道,我怎样才能实现这一目标。

感谢和问候,

SachinJadhav。

I am trying to make a call to javascript function from actionscript.

As of now, I am using 'ExternalInterface' and could achieve partial success.

I could make a call to function(without any scope resolution) like "scanDNA()", which is visible to all. But am not able to make a call to function(scope specified) like
"Eukarya.Animalia.Chordata.Vertebrata.Gnathostomata.Tetrapoda.Mammalia.scanDNA()".

Please let me know, how can I achieve this.

Thanks and Regards,

SachinJadhav.

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

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

发布评论

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

评论(3

比忠 2024-08-15 21:36:25

在JS中创建一个方法来调用该函数怎么样?

function scanDNAinSomeScope(){
    Eukarya.Animalia.Chordata.Vertebrata.Gnathostomata.Tetrapoda.Mammalia.scanDNA();
}

并使用 ExternalInterface 调用 scanDNAinSomeScope

更新:

是的,在这种情况下,您需要为每个范围创建一个函数。但是,您实际上仅为需要调用的函数创建。我相信在很多情况下您都不需要从 Flash 中调用不同范围的函数。

有一个解决方法,使用 JS 函数,例如:

function evil(str){
    eval(str);
}

它可能是一个安全漏洞。但我不是安全专家,所以我无法判断它实际上有什么问题......我只知道“eval isvilly”:P

How about creating a method in JS to call the function?

function scanDNAinSomeScope(){
    Eukarya.Animalia.Chordata.Vertebrata.Gnathostomata.Tetrapoda.Mammalia.scanDNA();
}

And call that scanDNAinSomeScope using ExternalInterface.

UPDATE:

Yes, in that case you need to create a function for every scope. But, you actually only create for functions that you need to call. I believe there wouldn't be many cases you need to call functions from different scope from Flash.

And there is a workaround, using a JS function like:

function evil(str){
    eval(str);
}

It may be a security hole. But I'm not security expert, so I can't tell what problem it actually has... I know "eval is evil" only :P

蔚蓝源自深海 2024-08-15 21:36:25

我从来没有注意到这有什么问题。你的 javascript 作用域结构是如何设置的?

也许在ExternalInterface调用中省略“()”可以解决这个问题。

如果我这样做

var animals = {}
animals.mammals = {}
animals.mammals.test = function() {
  return "whee";
}

并且在flash(CS4)中

var x:String = ExternalInterface.call('animals.mammals.test');
trace(x);

我会得到正确的结果。

I have never noticed any problems with this. How is your javascript scope structure set up?

Maybe leaving out the "()" in the ExternalInterface call could do the trick..

If I do

var animals = {}
animals.mammals = {}
animals.mammals.test = function() {
  return "whee";
}

and in flash (CS4)

var x:String = ExternalInterface.call('animals.mammals.test');
trace(x);

I get the correct result.

心如荒岛 2024-08-15 21:36:25

使用 javascript 伪协议效果很好。

Using the javascript pseudo protocol works well.

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