views:

14

answers:

1

Is there a way to detect if my Vector is out-of-range before performing an action?

I tried

if (myVector[i] != null || myVector != undefined) {
 // do stuff here
}

But I am getting an out-of-range error.

A: 

You need to check if the index is <= the length of the vector, and change the order of your tests. I'm not a Flash guy, but in most C-like languages, it'll look like this:

if (myVector != undefined /* Make sure the vector isn't null*/ && i < myVector.length() /*Make sure it's in range*/ && myVector[i] != null){
    // Do stuff here
}
Harper Shelby
ah! I see.that works now, thanks!
redconservatory