We help IT Professionals succeed at work.
Get Started

Listener value not updating with loop variable (URGENT)

andrewaiello asked
Last Modified: 2010-05-19
      I'm having a problem setting dynamic information to be used by a listener function.  The best way I can explain this is showing code and then going from there;  here it is:

for (i = 1; i <= 3; i++)
      var loadSlide = "PaxRoot.slide" + i;
      var slideContainer = "s" + i;
      this.createEmptyMovieClip(slideContainer, i);
      this["mclListener" + i] = new MovieClipLoader();
      this["mclListener" + i].onLoadComplete = function (targetMC)
                    targetMC.slideName = eval(loadSlide);              
      this["mclListener" + i].loadClip(eval(loadSlide), slideContainer);

Basically my problem is that, because the listener code is evaluated after the loading and not during the for loop; its value is always the same, the last value (done with loop) when the listener function is called.  i want it to step respectively with the loop, corresponding with the number of the listener.  Is there any way to force that value  to be like evaluated immediately or some such?      The max value of 3 is subject to change which is why i can't just enumerate each case and hardcode it that way.  Thank you.
Watch Question
Founder | CTO
Top Expert 2008
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE