Skip to main content
Participant
September 21, 2006
Question

clearInterval won't clear

  • September 21, 2006
  • 2 replies
  • 207 views
Aarrgh!

So forgive my ignorance, I am certain that this is a rather simple fix. Yet I cannot seem to find the solution in the forum.

Basically I wrote this code that draws a basic shape (and a key on top of it with a hint popup) that creates duplicate movieclips below it that spread out at different spacings. This works fine enough but when the spread function has done its job it does not clear the interval.

I also had an interval to fade the hint in and out, yet after the first time the hint faded in it automatically faded out on roll over instead of staying at full visibility. So I'm rather frustrated and am at the same time somewhat embarrassed as I'm certain I am wasting people's time with this issue.

At any rate here's the code (which all sits in frame 1). It's probably as simple as switching a sequence around someplace:


----------

stop();
var stdivl:Number = 5;
var paldepth:Number = 1000;
function spread(mcp:MovieClip, mcc:MovieClip, diff:Number) {
trace("MCP = "+mcp);
trace("MCC = "+mcc);
trace("DIFF = "+diff);
if (diff>0) {
if (mcc._x>=mcp._x+diff) {
clearInterval(stdivl);
} else {
mcc._x = mcc._x+1;
}
} else {
if (mcc._x<=mcp._x+diff) {
clearInterval(stdivl);
} else {
mcc._x = mcc._x-1;
}
}
}
_root.createEmptyMovieClip("palette", paldepth);
with (palette) {
lineStyle(0, 0x000000, 0);
beginFill(0x996633, 100);
moveTo(40, 0);
lineTo(460, 0);
curveTo(500, 0, 500, 40);
lineTo(500, 360);
curveTo(500, 400, 460, 400);
lineTo(40, 400);
curveTo(0, 400, 0, 360);
lineTo(0, 40);
curveTo(0, 0, 40, 0);
endFill();
_y = (Stage.height/2)-(_root.palette._height/2);
_x = (Stage.width/20);
}
palette.duplicateMovieClip("highlight1", paldepth-1);
palette.duplicateMovieClip("highlight2", paldepth-2);
palette.duplicateMovieClip("highlight3", paldepth-3);
with (highlight1) {
var h1c:Color = new Color(_root.highlight1);
h1c.setRGB(0xFFCC66);
_alpha = 50;
setInterval(spread, stdivl, _root.palette, _root.highlight1, 20);
}
with (highlight2) {
var h2c:Color = new Color(_root.highlight2);
h2c.setRGB(0xFF9900);
_alpha = 100;
setInterval(spread, stdivl, _root.palette, _root.highlight2, 40);
}
with (highlight3) {
var h3c:Color = new Color(_root.highlight3);
h3c.setRGB(0x800000);
_alpha = 100;
setInterval(testy, stdivl, "Here", "Really");
setInterval(spread, stdivl, _root.palette, _root.highlight3, -20);
}
_root.createEmptyMovieClip("key", paldepth+10);
with (key) {
beginFill(0xcccccc, 100);
lineStyle(1, 0x000000, 50);
moveTo(10, 5);
lineTo(15, 10);
lineTo(10, 15);
lineTo(5, 10);
lineTo(10, 5);
moveTo(10, 0);
curveTo(20, 0, 20, 10);
curveTo(20, 20, 10, 20);
curveTo(0, 20, 0, 10);
curveTo(0, 0, 10, 0);
endFill();
moveTo(20, 5);
beginFill(0xcccccc, 100);
lineTo(45, 5);
curveTo(55, 10, 45, 15);
lineTo(20, 15);
moveTo(45, 15);
lineTo(45, 20);
lineTo(40, 20);
lineTo(40, 15);
moveTo(35, 15);
lineTo(35, 25);
lineTo(30, 25);
lineTo(30, 15);
lineTo(25, 15);
lineTo(25, 20);
lineTo(20, 20);
lineTo(20, 15);
endFill();
_alpha = 50;
_xscale = _yscale=30;
_y = palette._y+palette._height-_root.key._height*2;
_x = palette._x+palette._width-_root.key._width*2;
}
_root.createEmptyMovieClip("keyhit", _root.key.getDepth()-1);
with (keyhit) {
moveTo(_root.key._x-5, _root.key._y-5);
lineStyle(1, 0x000000, 0);
beginFill(0x000000, 0);
lineTo(_root.key._x+_root.key._width+5, _root.key._y-5);
lineTo(_root.key._x+_root.key._width+5, _root.key._y+_root.key._height+5);
lineTo(_root.key._x-5, _root.key._y+_root.key._height+5);
moveTo(_root.key._x-5, _root.key._y-5);
endFill();
}
keyhit.onRollOver = function() {
_root.key._alpha = 100;
_root.createEmptyMovieClip("keyhint", _root.key.getDepth()+2);
with (keyhint) {
moveTo(0, 0);
lineStyle(1, 0x000000, 0);
beginFill(0xFFFF66, 100);
lineTo(50, 0);
lineTo(50, 50);
lineTo(30, 50);
lineTo(25, 60);
lineTo(20, 50);
lineTo(0, 50);
lineTo(0, 50);
lineTo(0, 0);
endFill();
_root.keyhint._x = _root.key._x-(_root.keyhint._width/4);
_root.keyhint._y = _root.key._y-_root.keyhint._height;
}
_root.createTextField("khtxt", _root.keyhint.getDepth()+1, _root.keyhint._x, _root.keyhint._y+5, _root.keyhint._width, _root.keyhint._height);
_root.khtxt.text = "Admin Panel:\rClick to Unlock";
_root.khtxt.multiline = true;
_root.khtxt.wordWrap = true;
_root.khtxt.selectable = false;
_root.khtxt.centered = true;
var fmt:TextFormat = new TextFormat();
with (fmt) {
align = "center";
color = 0x0000ff;
font = "Arial";
size = 8;
leftMargin = 2;
rightMargin = 2;
}
khtxt.setTextFormat(fmt);
keyhint.duplicateMovieClip("khshad", _root.key.getDepth()+1);
with (khshad) {
var black:Color = new Color(khshad);
black.setRGB(0x000000);
_alpha = 25;
_x = _root.keyhint._x+5;
_y = _root.keyhint._y+5;
}
};
keyhit.onRollOut = keyhit.onReleaseOutside=function () {
_root.keyhint._visible = false;
_root.khshad._visible = false;
_root.khtxt._visible = false;
_root.key._alpha = 50;
};

----------

Thanks again in advance.
This topic has been closed for replies.

2 replies

kglad
Community Expert
Community Expert
September 21, 2006
the correct usage of setInterval() and clearInterval() is:

Inspiring
September 21, 2006
Try reading the help files on how to call setInterval. You seem not to know
what you're doing there and seem confused between the interval time in
milliseconds and the interval id
--
Jeckyl