Copy link to clipboard
Copied
I have 3 arrays which are created from tags in an XML file, this part works fine.
Each index corresponds to each other, i.e. [0] of each is dashBurst (the animation), 1000 (the low damage range), and 2500 (the high damage range), respectively.
But when a function chooses dashBurst, and I use a trace statement to find it's index, it puts out -1.
This means that I can't get the damage values (specialList.indexOf('dashBurst')).
What is going on?
Ok, it was that I hadn't put the item in the array as a string.
I'll remember that in the future, and thanks a lot!
Copy link to clipboard
Copied
If you get a -1 as a result of using the indexOf method it means the item sought does not exist in the array.
Copy link to clipboard
Copied
post.user_wrote.label:
If you get a -1 as a result of using the indexOf method it means the item sought does not exist in the array.
I found a workaround where the damage index is +1 of the frame label index and it works fine.
I traced all the array's objects and it has everything in it's proper place.
So it exists, but it doesn't see it in the array at the time of this code running.
Copy link to clipboard
Copied
You might have traced the array's objects but whatever you are using quotes for in that code line is not (cannot be) an object. Try removing the quotes for a start if that is supposed to be an instance name.
Copy link to clipboard
Copied
It is a frame label, not an instance.
I removed the quotes (except for in the actual array), and I get the same thing.
Copy link to clipboard
Copied
Have you tried using double quotes?
Copy link to clipboard
Copied
I always use double quotes, it's a habit from writing. Should I be using single or double quotes more often?
Copy link to clipboard
Copied
If you always do then you missed doing it for the code you showed in the first posting for some reason. I only use double quotes in Actionscript code.
Try tracing the array at that same point in the code to make sure your array still carries what you think it should.
Copy link to clipboard
Copied
as you say, [0] is a animation instance, but specialList.indexOf('dashBurst') means looking for a String instance, right?
so you won't find 'dashBurst' in the array, but specialList[0].name is 'dashBurst'.
Copy link to clipboard
Copied
trace(specialList[0]);
then use the result here specialList.indexOf('result');
Copy link to clipboard
Copied
Convert the tags of the xml file to strings, however you're pushing the labels from the xml data, add ".toString();" after the node value.. example:
frameLabel[2] = xmlData.frame2.@label.toString();
Copy link to clipboard
Copied
Ok, it was that I hadn't put the item in the array as a string.
I'll remember that in the future, and thanks a lot!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now