4 Replies Latest reply on Aug 19, 2008 1:34 PM by Jed Schneider

    event listener not listening very well

    Jed Schneider Level 1
      HI, I am having problems with getting an eventListener to work properly.
      Right now I have 3 functions, one to loop through data and add the data to an arrayCollection, one to create a loader object and a third that is a completeHandler for the loader. There is an event listener function in the loader function that was working without the loop, now however it is not. To simplify the posted code my loop handler etc is stripped down to remove declarations. Any help is appreciated. Thank You.

        • 1. Re: event listener not listening very well
          Gregory Lafrance Level 6
          This no doubt has to do with the fact that Flex is asynchronous. I would have the ac.addItemAt(image, i) in the loadComplete method.
          • 2. Re: event listener not listening very well
            Jed Schneider Level 1
            Greg, good idea, but I tried that also. Unfortunately, when I do add the ac.addItemAt(image, i) into the loadComplete function it errors out of bounds because the .load call loads each of the files in succession without waiting for the loader to be done each time. So I get one instance of the array, but not all 5. So then I tried making the counter a module level variable and adding an if statement to the loadComplete function to check and see if the i value was less than the array.length of my input array and unfortunately that didn't work either.

            I am just learning this language, but there seems to have to be a way to deal with these instances. I don't know all the tools available but one that seems promising is the following:
            create an event
            var e:Event = new Event("watchTheStupidLoader");

            take out the loop completely and check the counter with a function;
            change the location of the array and increment the counter within that function, passing the next url as a return. I guess it would be a way to post-test the loop...

            any comment on trying it that way or a tool I'm overlooking?
            • 3. Re: event listener not listening very well
              Gregory Lafrance Level 6
              Your approach seems reasonable.
              • 4. Re: event listener not listening very well
                Jed Schneider Level 1
                I just thought I'd give a follow up on how I figured out this problem. Of course, this may not be the best solution, so if anyone wants to chime in and tell me how it should be done, please by all means...

                I removed the loop completely and rewrote the loadImage function with a new progressEvent handler. And as Greg suggested added the ac.adItem() call to the loadComplete function.