holtgrewe
12-14-2006, 01:47 PM
Here is a technique I use for multiple timed events on a page. This is another example of how versatile AMS6 is in developing APs.
ON PRELOAD:
-- >>>>> setup timer invervals for firing multiple timed events.
-- >>>>> set up 6 timers
myTimers_Max=6
-- >>>>> set up a duration for when each timer should be fired
myTimers_Duration={500,1000,1200,750,4000,2000}
-- >>>>> Set up an interval counter for each timer
myTimers_Interval={0,0,0,0,0,0}
Page.StartTimer(100);
pgTimer_Counter=100
ON TIMER:
-- >>>>> increment the interval for each timer
for x = 1, myTimers_Max do
myTimers_Interval[x] = myTimers_Interval[x] + pgTimer_Counter
end
-- >>>>> check if Individual timer event should be fired
for x = 1, myTimers_Max do
if myTimers_Interval[x] >= myTimers_Duration[x] then
myTimers_Interval[x] = 0; --clear the interval counter & get ready for next time
myTimer_Funct(x); -- execute the function for timer [x]
end
end
--Global Function:
function myTimer_Funct(whichTimer)
if whichTimer == 1 then -- Timer 1 has fired
-- >>>>> timer1 scripting
end
--etc. for the other timers
ON PRELOAD:
-- >>>>> setup timer invervals for firing multiple timed events.
-- >>>>> set up 6 timers
myTimers_Max=6
-- >>>>> set up a duration for when each timer should be fired
myTimers_Duration={500,1000,1200,750,4000,2000}
-- >>>>> Set up an interval counter for each timer
myTimers_Interval={0,0,0,0,0,0}
Page.StartTimer(100);
pgTimer_Counter=100
ON TIMER:
-- >>>>> increment the interval for each timer
for x = 1, myTimers_Max do
myTimers_Interval[x] = myTimers_Interval[x] + pgTimer_Counter
end
-- >>>>> check if Individual timer event should be fired
for x = 1, myTimers_Max do
if myTimers_Interval[x] >= myTimers_Duration[x] then
myTimers_Interval[x] = 0; --clear the interval counter & get ready for next time
myTimer_Funct(x); -- execute the function for timer [x]
end
end
--Global Function:
function myTimer_Funct(whichTimer)
if whichTimer == 1 then -- Timer 1 has fired
-- >>>>> timer1 scripting
end
--etc. for the other timers