Search code examples
actionscript-3flashnavigatetourl

Actionscript 3 - can't open multiple navigateToURL() instances at the same time


I am new to AS3, I want to open multiple browser tabs with flash.

I'm trying to simply start multiple instances of navigateToURL().

for each (var str:String in arrayofrequests) 
{
[...]
    try { navigateToURL(request, "_blank");}
[...]
}

but only the last instance of navigateToURL gets executed in the browser. I searched online and someone pointed out callLater could solve this issue. But every time I try to use callLater I get

 Error: Call to a possibly undefined method callLater.

I analyzed adobe documentation here: http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7b06.html

All objects that inherit from the UIComponent class can open the callLater() method.

How I do this? I tried to change my code to something like this

public class Main extends UIComponent

but it isn't working.


Solution

  • To start, UIComponent class is the base class for all visual components used in Flex ( like Label, Progressbar, ...), but I think that your are using Flash, so it's not the good way.

    Really I don't know why you want to open many urls in the browser in the same time ( and I think that your final user may be will not like that ), but you have to use some intervals between every navigateToURL() calls using a Timer object for example :

    var urls:Array = [
        'http://www.wikipedia.org',
        'http://www.ubuntu.com',
        'http://www.stackoverflow.com'
    ];
    
    var timer:Timer = new Timer(300, urls.length);
        timer.addEventListener(TimerEvent.TIMER, onTimer);
        function onTimer(e:TimerEvent):void {
            navigateToURL(new URLRequest(urls[timer.currentCount - 1]), '_blank');
        }
        timer.start();
    

    Hope that can help.