Skip to main content
Inspiring
May 6, 2014
Answered

How to trigger a AS function via JS?

  • May 6, 2014
  • 1 reply
  • 412 views

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>

This topic has been closed for replies.
Correct answer kglad

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.

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 6, 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.

Inspiring
May 8, 2014

you're amazing... thanks!

kglad
Community Expert
Community Expert
May 8, 2014

you're welcome.