dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: array skipping first letter

  1. #1
    Junior Member
    Join Date
    Sep 2000
    Posts
    11

    array skipping first letter

    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"+ii);
                
    //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;
        }

    Any help much appreciated.

  2. #2
    Junior Member
    Join Date
    Jul 2002
    Posts
    12

    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;
    }
    }

  3. #3
    Junior Member
    Join Date
    Jul 2002
    Posts
    12

    flas check it out

    flas check it out
    Attached Files Attached Files

  4. #4
    Junior Member
    Join Date
    Sep 2000
    Posts
    11
    Thank you thank you thank you! Works perfect!

    One more question I have never used _global before. Can you access it from any timeline kind of like _root?

  5. #5
    Junior Member
    Join Date
    Jul 2002
    Posts
    12

    _global

    _global is Player dependant variable.

    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

  6. #6
    Junior Member
    Join Date
    Sep 2000
    Posts
    11
    Thats pretty cool. I will have to mess around with it. Thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center