Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to trigger a AS function via JS?

Participant ,
May 06, 2014 May 06, 2014

I need to trigger a AS function when a user close the browser window. This is what I've done so far... but no luck.

AS:

import flash.external.*;
function test1() {
//do something
}


JS:

<script type="text/javascript">  
  window
.onbeforeunload = function(){
  test1
();
  
return 'text here' };
</script>

TOPICS
ActionScript
353
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 06, 2014 May 06, 2014

use:

AS:

import flash.external.*;

ExternalInterface.addCallback("jsCallF",null,test1);
function test1(s:String) {
//do something with s
}


JS:

<script type="text/javascript">  

function thisMovie(movieName) {

  if (navigator.appName.indexOf("Microsoft") != -1) {

  return window[movieName]

  }

  else {

  return document[movieName]

  }

}
  window
.onbeforeunload = function(){
  thisMovie("your_swfs_embed_tag_name").jsCallF('text here');
  
};
</script>

and you'll need to use embedding code compatibl

...
Translate
Community Expert ,
May 06, 2014 May 06, 2014

use:

AS:

import flash.external.*;

ExternalInterface.addCallback("jsCallF",null,test1);
function test1(s:String) {
//do something with s
}


JS:

<script type="text/javascript">  

function thisMovie(movieName) {

  if (navigator.appName.indexOf("Microsoft") != -1) {

  return window[movieName]

  }

  else {

  return document[movieName]

  }

}
  window
.onbeforeunload = function(){
  thisMovie("your_swfs_embed_tag_name").jsCallF('text here');
  
};
</script>

and you'll need to use embedding code compatible with the externalinterface class.  swfobject works and there's code shown in the adobe help files that also works.

and you'll need to use the correct name in place of your_swfs_embed_tag_name.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 07, 2014 May 07, 2014

you're amazing... thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 07, 2014 May 07, 2014
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines