0

In the below code, indexOf() is always returning -1. The array being searched definately has the values within.

We've tried converting the checked integer into a string in case the array has string formats within, no luck there either.

If anybody could shed any light that would be great!

AS3

var c:int = 0; var storedCachesShared:SharedObject = SharedObject.getLocal("cacheStore"); var storedCaches:Array = storedCachesShared.data.cacheArray; trace(storedCaches); // 1, 2 trace(storedCaches.indexOf(c+1)); // Always returns -1 if(storedCaches.indexOf(c+1) < 0){ storedCaches.push([c+1]); storedCachesShared.flush(); } 

Many thanks, Nick

0

1 Answer 1

2

This line looks problematic. It is adding an Array (as you surrounded it with []) to the end of the existing Array:

storedCaches.push([c+1]); 

I think you mean to add an int, so you need this:

storedCaches.push(c+1); 

indexOf is returning -1 because it is looking for an int but storedCaches is an Array of Arrays.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.