PDA

View Full Version : array problem, or wrong approach maybe


frankyk
10-08-2007, 01:19 PM
Hi there,

Although I am not new to Flash, I am not a great mind when it comes to scripting...



I am trying to get a true or false statement to see if a certain value is in a list: this code is only to give you an idea, it is not working as it is now, i know...

array4=["ca1", "dc19"];
array3=["da21", "da22", "dj10"];
array2=["aa3", "da6", "da8", "da11"];
array1=["aa5", "da1", "da2", "da4", "da5", "da13", "da19"];


_root.subsub = false;

if (_root.varchapter+_root.varsubcat+_root.varimg == array4) {
_root.subvarimg = 4;
_root.subsub = true;
}
if (_root.varchapter+_root.varsubcat+_root.varimg == array3) {
_root.subvarimg = 3;
_root.subsub = true;
}
if (_root.varchapter+_root.varsubcat+_root.varimg == array2) {
_root.subvarimg = 2;
_root.subsub = true;
}
if (_root.varchapter+_root.varsubcat+_root.varimg == array1) {
_root.subvarimg = 1;
_root.subsub = true;
}

Any help is greatly appreciated!
cheers,
Franky

Noct
10-08-2007, 03:47 PM
Welcome aboard,

Well, it definately won't work as written, you're right about that.
you need to give some more info...

What are these three variables you are adding together and evaluating against the arrays?

Is it something like this?
varchapter = a
varsubcat = a
varimg = 5
If so, then the problem is jus that you are trying to evaluate that against an entire array, when it would only be equal to one value in that array.
The above values would == array1[0], or the first place in that array.
Trying to evaluate them against the array itself is asking this:
if ("aa5" == "aa5", "da1", "da2", "da4", "da5", "da13", "da19")

frankyk
10-08-2007, 09:05 PM
Thanks for your help.
But this solution checks if the first variable equals the whole row of variables doesn't it? At least it didn't work out in my test, it returned:
_root.subvarimg = 1;
on all values.
I need to check whether
_root.varchapter+_root.varsubcat+_root.varimg
equals any one of the values in that row.

tg
10-08-2007, 10:36 PM
you looking for something that will search thru each array for a specific value?
maybe im misunderstanding... if not try this:

array4=["ca1", "dc19"];
array3=["da21", "da22", "dj10"];
array2=["aa3", "da6", "da8", "da11"];
array1=["aa5", "da1", "da2", "da4", "da5", "da13", "da19"];

_root.subsub = false;
//var myVar='ca1';
//var myVar='da1';
var myVar='zzz1';
foundInArray = function(value,a)
{
var found = false;
var i = 0;
trace(a);
trace(value);
for(i=0; i<a.length; i++){
if( a[i] == value ) found = true;
}
return found;
}

for (var x=1;x<5;x++){
_root.subsub=foundInArray(myVar,this['array'+x]);
if(_root.subsub){
_root.subvarimg=x;
break;
}
}
trace(_root.subsub+":"+_root.subvarimg);

frankyk
10-09-2007, 11:02 AM
thanks tg, this code is too avanced for me though, so I don't understand everything. when i ran it, it returned:
zzz1
false:0

maybe i should explain: the elements in the arrays stand for a path to directories like: d/b/14
I have 4 arrays, and each of them stand for:
array 1: all elements in this array have 1 image in the directory
array 2: all elements in this array have 2 images in the directory
array 3: all elements in this array have 3 images in the directory
array 4: all elements in this array have 4 images in the directory

when i know how many images the directory has, i can tell the buttons in de subsub-thingy that they have to go back to image 1 after the last image has been presented.

omg, this project is turning into a mess, but the client decided halfway that they wanted subsub-directories...

tg
10-09-2007, 04:41 PM
right. it returned zzz1 because that is what i was searching for in your arrays... and it doesnt exist.

ok. so i guess i mis understood your original post...
hrm... yeah. sounds like a real nightmare.


i gues i was confused by your comment in your post here :

I am trying to get a true or false statement to see if a certain value is in a list


the above code should do this....

comment out the line with zzz1 (which doesnt exist in your arrays) and replace it with 'aa3' (which does). it will trace out: 'true:2'
true meaning teh value was found in one of your arrays, & 2 indicating it was found in array2.