简体   繁体   English

在ActionScript中调用JavaScript函数

[英]Call JavaScript function within ActionScript

I'm not familiar with ActionScript and for some reason the following code won't work, although it was mentioned that way in a tutorial: 我不熟悉ActionScript,由于某种原因,以下代码无法使用,尽管在教程中是这样提到的:

class Dummy {

  function Dummy() {
  }

  static function main(mc) {

    getURL("javascript:alert('works!')");
  }

}

I used "mtasc" to compile the script. 我使用“ mtasc”来编译脚本。

when you're embedding the flash file in your page are you setting allowscriptaccess="true" 当您在页面中嵌入Flash文件时,是否设置了allowscriptaccess =“ true”

so like: 像这样:

<embed src="flash.swf" allowscriptaccess="true"></embed>

Did you specify a document class for your flash file? 您是否为Flash文件指定了文档类? You aren't actually calling the function that calls your javascript anywhere in the code above. 您实际上并没有在上面的代码中的任何地方调用调用JavaScript的函数。 If you put the "getURL" line into function Dummy and specify Dummy as your document class, your code will execute. 如果将“ getURL”行放入Dummy函数中并指定Dummy作为文档类,则将执行代码。 Otherwise, within dummy, make a call to main(). 否则,在虚拟对象内,调用main()。 Also just a note that currently there's no reason to have (mc) as a passed parameter in that function. 还要注意,当前没有理由在该函数中将(mc)作为传递的参数。

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

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