mercredi 28 septembre 2016

Split is not a function?

I have this code I was testing with:

var test:String="Hello there; im zane"
var parts:Array=test.split(";");
trace(parts)
trace(parts[0])
var randomnum:Number=0; 
stage.addEventListener(Event.ENTER_FRAME, code)
function code(c:Event):void{
    if(parts[randomnum] != undefined && parts[randomnum] != null){
        parts[randomnum]=parts[randomnum].split(" "); 
        randomnum+=1
        trace(parts[randomnum])
        }
    else{
        randomnum=0
        }
}

And there is an error with this parts[randomnum]=parts[randomnum].split(" ");. Flash says that split is not a function (

TypeError: Error #1006: split is not a function. at Untitled_fla::MainTimeline/code()

)

Earlier in this project, I used the split function with a different part of the variable, and I also tried parts[0]=parts[0].split(" ") out of the event and it worked fine.

What I'm trying to find out is, why does a split command not work in this scenario? Am I doing something wrong?

Aucun commentaire:

Enregistrer un commentaire