Seeker
Seeker

Reputation: 2475

long run error after calling the javascript method from the action script

I am trying to call a method of a javascript from the actionscript using the ExternalInterface. Here is the code in action script

private function onKickEvent(e:LogoutEvent):void{
                ExternalInterface.call("LoginFound","message");
                return;
        }

And this is my javascript mwthod

function LoginFound(message){
        alert(message);
    anotherInstanceExists=true;

}

Everything is working fine, but the only thing is when act on the alert box which is shown in the javascript after some 20 secs, the exception is thrown from the flash player that a script has been running longer than expected time 15 sec.

How can i avoid this?

Upvotes: 1

Views: 153

Answers (3)

avladov
avladov

Reputation: 851

Best way to fix this issue is to add setTimeout inside your javascript on the alert line. It should look like this:

setTimeout(function(){ alert(message) }, 1);

By doing it this way execution won't stop because of the alert.

Upvotes: 3

Exhausted
Exhausted

Reputation: 1885

I think your onKickEvent is called frequently

so that the javascript is called regularly. finally the browser timeout event

occurs. It always happen in recursive function.

Upvotes: 0

Engineer
Engineer

Reputation: 48793

When you call js function from the actionscript, that function have to work and return value not longer than in 15 sec. Javascript works in single thread,and when you call LoginFound function, alert stops farther executions on the thread.

function LoginFound(message){
    alert('something');
    //Nothing will be executed unless `alert` window will be closed        
}

However you can handle such situation (the execution,which is longer than 15 sec) in Actionsript by using try/catch:

private function onKickEvent(e:LogoutEvent):void{
    try{
        ExternalInterface.call("LoginFound","message");
    }catch(e:Error){
        //Do something
    }
}

Upvotes: 2

Related Questions