简体   繁体   中英

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:

class Dummy {

  function Dummy() {
  }

  static function main(mc) {

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

}

I used "mtasc" to compile the script.

when you're embedding the flash file in your page are you setting allowscriptaccess="true"

so like:

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

Did you specify a document class for your flash file? You aren't actually calling the function that calls your javascript anywhere in the code above. If you put the "getURL" line into function Dummy and specify Dummy as your document class, your code will execute. Otherwise, within dummy, make a call to main(). Also just a note that currently there's no reason to have (mc) as a passed parameter in that function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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