Paul:

I understand what you're trying to do (make a time-delay slide show of
images).
Using setInterval for that is fine, but you have to make sure you're
using it correctly.

Calling setInterval will set up a flash system timer that will call your
function every X milliseconds.
It will keep going, and keep calling that function (every X
milliseconds), until it's stopped.

Hence, there is no reason for you to be calling setInterval in a loop
and setting up 5 timers (that will each repeat forever).  Simply have 1
timer, that repeats 5 times, then you stop it.

To do this in simplified code:

        //set up the call count.
        _root.timerCalls = 0;

        //make the function that will be called.
        function foo()
        {
          trace("Timer function got called!");
          
          if(_root.timerCalls++ == 4) 
          {
                trace("Max calls reached.  Stopping timer...");
                clearInterval(_root.myTimerID);  //timer will never get
called again.
                _root.timerCalls = 0; //reset counter
          }

          //do "stuff" (every 1sec).
        }
        
        //make the timer, and start it.
        _root.myTimerID = setInterval(foo, 1000); //system will call
foo() every second until you stop it.  Timer ID gets stored into
_root.myTimerID.

This is just one way to do it.  In your timer function, you'll implement
your code for loading the new image, and taking away the old one.

-=matt


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Paul V.
Sent: Wednesday, February 28, 2007 5:03 PM
To: Flashnewbie Mailing List; Flashcoders mailing list
Subject: [Flashcoders] Getting frustrated. regarding set Interval,and
for loop.

Let me explain the problem I am having and then I will send you some
code.  I want to load up images in a slide show with set interval, with
the images being called image1 image2 image 3 etc.  I want to be coding
a dynamic slide show so that if I change the images I can just replace
the mc images.

here is the code I am working on, I am a little new to setInterval
(completely new to that function actually) - I do understand the basic
syntax, 
setInterval( function (){ //entire function here;},1000);

But I don't know how to run a for loop inside it and pass a variable to
it. (I am a newbie).

function loadImages(){        //Ihave this here so I can run an external
for loop.
     for(i=1;i<6;i++){            
      setInterval(function(){     //set interval and begins anonymous
function  i.e function() -no name   
      attachMovie("image"+i,"image"+i,41);   //trying to attach the
images, image1 - image5
      image = eval("image"+i);                    //instance assigned to
variable  'image'
      image._x = ((Stage.width / 2)-(image._width/2));   //positioning
      image._y = (yFactor);
//positioning
      oldwidth = image._width;
//saving dimensions for resizing formula
      oldheight = image._height;                                //saving
dimensions for resizing formula
 
      image._height = yheight;                                 //image
height set to variable  
      image._width = ((oldwidth*yheight)/oldheight);   //image width set
to proportions of original 
    },1000);
//interval to 1 sec. 1000 milliseconds         
 }
//end for loop
}                                                           //end
container function 

I am trying to set the images up for a second and then have them switch.
Help me out if you you know a solution.  Or even if you see some obvious
errors. Like I said I am new with the set interval.  by the way if you
like that little resizing technique, you can use it. Thank you.

Looking forward to a response on this one.

Paul Vdst
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to