all groups > flash actionscript > september 2004 >
You're in the

flash actionscript

group:

clearInterval - speedy problem



clearInterval - speedy problem erjee
9/10/2004 9:34:51 PM
flash actionscript: i try to make photos move left to right (www.bluesinschoten.be)
its not working with actionscript2 defined
the clearinterval seems not to work
Please ... anyone ?

// set the info about the content
contentRight = content_mc._x;
contentLeft = 789 - content_mc._width;

function moveContent(s) {

contentGoal = contentRight - section[s]._x;
// make sure it?s not off the screen!
if (contentGoal<contentLeft) {
contentGoal = contentLeft;
}
moveTo(contentGoal);
}


// sliiiiding :-)

function moveTo(contentGoal) {
this.contentGoal = contentGoal;
move_int = setInterval(setX,70);
}


function setX() {
newX=(content_mc._x+contentGoal)/2;
if(Math.abs(newX-contentGoal) < 1) {
content_mc._x = contentGoal;
// ITS LOOPING HERE THOUGH MATH ABS ... < 1
clearInterval(move_int);
} else {
content_mc._x = newX;
}
}


// ----------------- ONROLLOVER ----------------------
_root.info_bt.onRollOver = function() {
moveContent(0);
}
_root.spine_bt.onRollOver = function() {
moveContent(1);
}
Re: clearInterval - speedy problem kglad
9/11/2004 12:28:48 AM
you're defining more than one setInterval using the same name. that will
leave, at least, one running. to remedy use an array to define the different
set intervals or take steps to ensure that more than 1 setInterval() cannot
execute at the same time.
Re: clearInterval - speedy problem erjee
9/13/2004 6:45:07 PM
Could you be more specific ?
I thought the variable is needed as an ID and through the trace method i see
the Id (variable) is augmenting each time ...
So it's unique but i think the problem is where i call the function setX.
And indeed, it's always the last call to the setX method that never stops.
So how can an array solve the problem ?
Is it possible to call a function by an 'array-ingredient' :

move_int = setInterval(setX(arrayIndex ?),70);

Thanks for you reply !
Re: clearInterval - speedy problem kglad
9/14/2004 1:18:29 AM
the id is unique but how do you clear that interval when your variable
containing that id value changes? to remedy you can use an array:

move_intA=new Array();
ivar=0;
function moveTo(contentGoal) {
this.contentGoal = contentGoal;
move_int[ivar] = setInterval(setX,70,ivar);
ivar++;
}


function setX(ivar) {
newX=(content_mc._x+contentGoal)/2;
if(Math.abs(newX-contentGoal) < 1) {
content_mc._x = contentGoal;
// ITS LOOPING HERE THOUGH MATH ABS ... < 1
clearInterval(move_int[ivar]);
} else {
content_mc._x = newX;
}
}
Re: clearInterval - speedy problem erjee
9/18/2004 8:00:25 AM
thank you VERY much !!!

Re: clearInterval - speedy problem kglad
9/18/2004 3:25:54 PM
AddThis Social Bookmark Button