Why when I publish my movie it skips the first letter of my array. Everything seems to load into the array okay but, when the text moves into place it skips the first letter. I fixed it by making the first letter repeat in my text file but, I would like to know what I am doing wrong.
I have a text file named data.txt inside of the text file dataString=Work Please
On the stage I have an empty mc with the code
PHP Code:
//load the text file
onClipEvent(load) {
loadVarsText = new LoadVars();
loadVarsText.load("data.txt");
loadVarsText.onLoad = function(success) {
if (success) {
trace ("done loading: "+this.dataString);
//starting positions
startXpos = 100;
startYpos = 100;
nextX = 0;
elapsedTime = 0;
enterTime = 0;
//i = 0;
//put text from file in array
newLetters = new Array();
newLetters = this.dataString.split("");
trace("length: "+ newLetters.length);
} else {
//oops no text file loaded
trace ("not loaded");
}
}
}
onClipEvent(enterFrame) {
if (elapsedTime>100) {
enterTime = getTimer();
if (i<this.newLetters.length) {
/*attach a mc with from library link named letter
inside the letter mc is animated mc instance named animated
inside the animated mc is text box instance named letterContainer*/
newClip=_root.attachMovie("letter", "letter"+i, i);
//put the letter from the array into the animated text box
newClip.animated.letterContainer.text = newLetters[i];
trace("textWidth: "+newClip.animated.letterContainer.textWidth);
//move the newly made clip
newClip._x = nextX;
newClip._y = startYpos;
//place the mc next to the last mc
nextX = newClip._x + newClip.animated.letterContainer.textWidth;
++i;
elapsedTime = 0;
}
} else {
elapsedTime = getTimer()-enterTime;
}
}
the variable i is not initialized that's the problem
dear rasphswirl,
the variable i is not initialized that's the problem
the complete code is here
/load the text file
onClipEvent(load) {
_global.counter=0;
loadVarsText = new LoadVars();
loadVarsText.load("data.txt");
loadVarsText.onLoad = function(success) {
if (success) {
trace ("done loading: "+this.dataString);
//starting positions
startXpos = 100;
startYpos = 100;
nextX = 0;
elapsedTime = 0;
enterTime = 0;
//i = 0;
//put text from file in array
newLetters = new Array();
newLetters = this.dataString.split("");
trace("length: "+ newLetters.length);
trace(newLetters);
} else {
//oops no text file loaded
trace ("not loaded");
}
}
}
onClipEvent(enterFrame) {
if (elapsedTime>100) {
enterTime = getTimer();
if (_global.counter<this.newLetters.length) {
/*attach a mc with from library link named letter
inside the letter mc is animated mc instance named animated
inside the animated mc is text box instance named letterContainer*/
newClip=_root.attachMovie("letter", "letter"+_global.counter, _global.counter);
//put the letter from the array into the animated text box
newClip.animated.letterContainer.text = newLetters[_global.counter];
trace("textWidth: "+newClip.animated.letterContainer.textWidth);
//move the newly made clip
newClip._x = nextX;
newClip._y = startYpos;
//place the mc next to the last mc
nextX = newClip._x + newClip.animated.letterContainer.textWidth;
++_global.counter;
elapsedTime = 0;
}
} else {
elapsedTime = getTimer()-enterTime;
}
}
if you load 5 movies in a player into diffent levels you can declare a variable in one level as _global.var1, you can use it in other swf's loaded with the same player