-
[as2] clearInterval Problem
I have made a menu, that reads its content out of an XML file.
When you move over the buttons, the scale, and alpha is set to 100.
When you leave the button it is resetted to it's original size/position.
But, if you move to fast over the buttons, they disappear. It's like the file doesn't call the clearInterval:
Here is the code:
code:
//Begin of code
a=3
mcBalk=this.attachMovie("balk_mc","mc_balk",0)
mcBalk._x=Stage.width-(mcBalk._width)
mcBalk._y=(Stage.height/2)-(mcBalk._height/2)
menu_XML=new XML()
menu_XML.ignoreWhite=true
menu_XML.onLoad=function(OK){
if(OK){
Menu_inladen(this.firstChild)
}
else{
trace("No valid XML-file")
}
}
menu_XML.load("XML/menu.xml")
function Menu_inladen(data){
aantalMenuItems=data.childNodes.length
arrMenuItems=[]
for (i=0;i<aantalMenuItems;i++){
ItemNaam=data.childNodes[i].childNodes[0].firstChild
UrlImg=data.childNodes[i].childNodes[1].firstChild
arrMenuItems.push({nr:i, name:ItemNaam, UrlImg:UrlImg});
}
for (i=0;i<arrMenuItems.length;i++){
mc=this.attachMovie("button_mc","mc_button"+i,i+1)
mc._xscale=50
mc._yscale=50
mc._alpha=50
mc._x=470
mc._y=50+(i*80)
mc.obj=arrMenuItems[i]
mc.obj.mc=mc
UrlImg=mc.obj.UrlImg
mc.image_mc.loadMovie(UrlImg)
mc.onRollOver=function(){
RollOver(this.obj)
}
mc.onRollOut=function(){
RollOut(this.obj)
}
}
}
function RollOver(obj){
intervalROver=setInterval(IntervalRollOver,1,obj)
}
function RollOut(obj){
intervalROut=setInterval(IntervalRollOut,1,obj)
}
function IntervalRollOver(obj){
if(obj.mc._xscale<100){
obj.mc._xscale=obj.mc._yscale+=a
obj.mc._alpha+=a
}
else{
clearInterval(intervalROver)
}
}
function IntervalRollOut(obj){
if(obj.mc._xscale>50){
obj.mc._xscale=obj.mc._yscale-=a
obj.mc._alpha-=a
}
else{
clearInterval(intervalROut)
}
}
// End of code
Last edited by VisuaPix; 01-24-2005 at 04:30 PM.
-
All your menu items are using the same two variables, intervalROver and intervalROut, to store their intervals. If you trigger the rollOver of one item before the rollOver action of the previous item has finished, then the interval identifier for the first rollOver action is lost, and there is no way to cancel it.
Try storing each interval as a property of the object:
code:
function RollOver(obj){
obj.intervalROver=setInterval(IntervalRollOver,1,o bj);
}
Also, if you enclose your code between tags (AS) and (/AS), but replace the parentheses with square brackets, it will be formatted nicely.
Unless otherwise specified, all code goes in Frame 1 of main timeline. FlashGizmo.com
-
I'm sorry, but it still doesn't work
-
To debug, try putting in trace messages. After you do setInterval,
do trace("Setting interval " + obj.intervalROver). Just before clearInterval, put a similar trace action. See if you get intervals set but not cleared.
An ugly brute-force method to make sure intervals are cleared uses the fact that all the intervals are numbers.
code:
function clearAllIntervals() {
for(var i = 100; i >= 0; i--) {
clearInterval(i);
}
}
Unless otherwise specified, all code goes in Frame 1 of main timeline. FlashGizmo.com
-
mike to the rescue again for the second time this week.
I had exactly the same problem as visualPix..
i was seting an interval and clearing it after it had done its job but if the setting was done faster than the clearing then the clearing doesnt clear even though it has exactly the same refs.
the brute force method killed the bugger.
-------------------------
for (var a = 0; a<=100; a++) {
clearInterval(a);
}
-------------------------
mojito
-
Designer, Programmer, Musician
Originally Posted by mojito
mike to the rescue again for the second time this week.
I had exactly the same problem as visualPix..
i was seting an interval and clearing it after it had done its job but if the setting was done faster than the clearing then the clearing doesnt clear even though it has exactly the same refs.
the brute force method killed the bugger.
-------------------------
for (var a = 0; a<=100; a++) {
clearInterval(a);
}
-------------------------
mojito
That helped me! THanks. I wish there was another way of stopping the interval not using brute force...
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|