user2464564
user2464564

Reputation: 3

as3 how to stop an infinite loop?

I have a website, and basically I want to use flash to automatically redirect the web site to another with as soon as its load. But it keeps rapidfiring, and has even crashed my computer at one point. How can I set this to only only send the user once.

addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);

function fl_EnterFrameHandler(event:Event):void
{
//navigateToURL(new URLRequest("http://www.levittproperties.com/sitebuildercontent/sitebuilderfiles/homepage.swf"), "_self");
trace("Entered frame");
}

The '//' is just incase you try in your flash. I don't want you to crash too. The 'trace' is sufficient to see what I'm talking about.

Upvotes: 0

Views: 1149

Answers (2)

Ivan Chernykh
Ivan Chernykh

Reputation: 42166

Try to do as Garry Wong said. But if you must use the ENTER_FRAME for some reasons , so use it only once , like this:

addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);

function fl_EnterFrameHandler(event:Event):void
{
    removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
    navigateToURL(new URLRequest("http://www.levittproperties.com/sitebuildercontent/sitebuilderfiles/homepage.swf"), "_self");     
}

Upvotes: 0

phpisuber01
phpisuber01

Reputation: 7715

All you need to do is kill the event listener if you're already on your target page, consider the following:

import flash.external.ExternalInterface;

addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);

function fl_EnterFrameHandler(event:Event):void
{
    var gotoURL:String = "http://www.levittproperties.com/sitebuildercontent/sitebuilderfiles/homepage.swf";
    var currentURL:String = ExternalInterface.call("window.location.href.toString");
    if(gotoURL != currentURL) {
        navigateToURL(new URLRequest(gotoURL), "_self");
    } else {
        Event.currentTarget.removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
    }
}

Upvotes: 1

Related Questions