0

I need to call a actionscript 2 function via js when the browser close button is clicked. How can I do this? I tried this but no luck.

AS2

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

JS

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

2 Answers 2

3

I could achieve this in actionscript 3.

JS code:

window.onbeforeunload = function(){
            var flashObj = document.getElementById('fla');
                flashObj.changeText("closing");
             return 'text here'
              }; 

AS code:

ExternalInterface.addCallback('changeText', changeText);
ss.text = "ello"
function changeText(val)
{
    ss.text = val;
}

Here ss is a dynamic text field.

Sign up to request clarification or add additional context in comments.

Comments

0

this probably isn't possible, i've used onbeforeunload, to load a image on a server, which is actually a php script

or at least if it does work will be browser specific, as chrome like to block x-script and ajax calls on the onbeforeunload function, would expect it to pull the memory from the flash instance too

However something very close should be possible

if possible move your logic into javascript, use the grab image hack for server side communication, and return a string to pose the user a "Are you sure you want to quit this excellent page?" style question

ps i don't mean rewrite everything in javascript, just maybe poll from javascript what the user is doing, so when the user closes the page, the javascript can go "But your currently editting your awesome XXXXX image ?" where XXXXX was the last thing javascript polled from as2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.