0

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.

  • 1
    I don't know your background on AS3, but what you've written there tells the program to execute the navigateToURL command EVERY SINGLE FRAME. That's the function of the Event.ENTER_FRAME - to execute your specified function every frame. Why don't you just write and execute your own function - once - to achieve what you want? – Garry Wong Jun 07 '13 at 18:34

2 Answers2

1

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);
    }
}
phpisuber01
  • 7,585
  • 3
  • 22
  • 26
0

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");     
}
Ivan Chernykh
  • 41,617
  • 13
  • 134
  • 146