Groups | Blog | Home
all groups > flash actionscript > august 2006 >

flash actionscript : Inf Loop


NO[at]SPAM C1D
8/1/2006 7:29:39 PM
The script below loops endlessly, I need it to stop after the last line of
text. Help? >:(

// dimension of stage
stageWidth = 500;
stageHeight = 300;
// speed of scrolling text
scrollRate = 1;
// count used to wait between each line of text
waitCount = 0;
// current depth at which to place text lines
depth = 1;
// number of stars
starNum = 100;
// clip to hold stars
this.createEmptyMovieClip("stars", 0);
// places stars on stage
for (i=0; i) {
s = stars.attachMovie("star", "star"+i, i);
s._x = Math.random()*stageWidth;
s._y = Math.random()*stageHeight;
s._xscale = s._yscale=(Math.random()+.2)*100;
}
delete s;
delete i;
// text to be scrolled
scrollText = [];
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
scrollText.push("TEST");
// text formatting for scrolling text
tf = new TextFormat();
tf.color = 0xFFE700;
tf.size = 32;
tf.font = "scrollFont";
tf.underline = 1;
// amount of time to wait between placing each line
lineWait = (tf.size/scrollRate)*1;
// holds references to all the lines
lines = [];
// function called at set interval to check status of load
// clip is the movieclip that is loading content
assessLoad = function (clip) {
// delete these two lines and uncomment the above lines upon publishing
// scrolls lines
moveLines();
// if clip is completely loaded, final line added
};
// adds and formats a new line to scrolling text
createLine = function () {
this.createTextField("t"+depth, depth, stageWidth/2, stageHeight, 0, 0);
var t = this["t"+depth];
depth++;
t.embedFonts = 1;
t.setNewTextFormat(tf);
t.autoSize = "center";
// used to decrement alpha without dealing directly with _alpha property
t.alpha = 100;
t.text = scrollText.shift();
// stores reference to line
lines.push(t);
};
// scrolls lines up
moveLines = function () {
// time to wait before adding next line
waitCount++;
if (waitCount>lineWait) {
waitCount = 0;
createLine();
}
// runs through each line and moves it
for (var i in lines) {
var t = lines[i];
// scales it down
t._xscale = t._yscale -= scrollRate*.2;
// moves it up
t._y -= scrollRate*(t._xscale/100);
// reduces its alpha
t.alpha -= scrollRate*.1;
t._alpha = t.alpha;
// removes it once it is too small
if (t._yscale<=5) {
t.removeTextField();
lines.shift();
i--;
}
}
updateAfterEvent();
};
// used at end of preload
gotoSite = function () {
clearInterval(preload);
clearInterval(waitInterval);
for (var i in lines) {
lines[i].removeTextField();
}
};
// adds first line then removes underline formatting
createLine();
tf.underline = 0;
preload = setInterval(assessLoad, 50, this);
Darr_darshan
8/3/2006 12:50:17 PM
check your for loop please

for(i=0;i<20;i++)
it should be something like this
AddThis Social Bookmark Button