Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Question about Variables

New Here ,
Mar 29, 2013 Mar 29, 2013

This is probably a fairly simple question, but I've never seen any documentation on it so I'm not sure of the answer.

Let's say I have the following code:

var myLoader:URLLoader;

function someFunction(){

     myLoader = new URLLoader();

     myLoader.addEventListener(Event.COMPLETE, onComplete);

     myLoader.load(new URLRequest("something"));

     function onComplete(e:Event):void{

          //Some Code.

     }

}

function someOtherFunction(){

     myLoader = new URLLoader();

     myLoader.addEventListener(Event.COMPLETE, onComplete);

     myLoader.load(new URLRequest("somethingElse"));

     function onComplete(e:Event):void{

          //Some Code.

     }

}

My question is, would it be possible for these two URLLoaders to interfere with each other, for instance if they were executed at the same time--even though they're confined to different functions? Thanks for the help.

TOPICS
ActionScript
386
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 29, 2013 Mar 29, 2013

they're not going to get mixed up but the only thing that would load would be the last myLoader.load() that executes.

if you wanted both to load, you would need to use two different loaders.

Translate
Community Expert ,
Mar 29, 2013 Mar 29, 2013

that code is problematic.  you only have one reference for two (or more) urlloaders.

if you only need one, use one:

var myLoader:URLLoader=new URLLoader();

function someFunction(){

     myLoader.addEventListener(Event.COMPLETE, onComplete);

     myLoader.load(new URLRequest("something"));

     function onComplete(e:Event):void{

          //Some Code.

     }

}

function someOtherFunction(){

     myLoader.addEventListener(Event.COMPLETE, onComplete);

     myLoader.load(new URLRequest("somethingElse"));

     function onComplete(e:Event):void{

          //Some Code.

     }

}

if you need more than 1, give them different references.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 29, 2013 Mar 29, 2013

Kglad, thanks for the reply. in your example you're using a single URLLoader in different functions, so if those functions were executed at the same time would the eventListeners potentially get mixed up since you're adding 2 of them to the same URLLoader, or would they remain separate since they're confined to different functions? That's essentially what I was trying to find out with my original question.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 29, 2013 Mar 29, 2013
LATEST

they're not going to get mixed up but the only thing that would load would be the last myLoader.load() that executes.

if you wanted both to load, you would need to use two different loaders.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines