Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Array Has -1 index

Participant ,
Oct 09, 2015 Oct 09, 2015

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?

TOPICS
ActionScript
761
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Oct 12, 2015 Oct 12, 2015

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!

Translate
LEGEND ,
Oct 09, 2015 Oct 09, 2015

If you get a -1 as a result of using the indexOf method it means the item sought does not exist in the array.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 10, 2015 Oct 10, 2015

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 10, 2015 Oct 10, 2015

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 11, 2015 Oct 11, 2015

It is a frame label, not an instance.

I removed the quotes (except for in the actual array), and I get the same thing.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 11, 2015 Oct 11, 2015

Have you tried using double quotes?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 12, 2015 Oct 12, 2015

I always use double quotes, it's a habit from writing. Should I be using single or double quotes more often?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 12, 2015 Oct 12, 2015

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2015 Oct 09, 2015

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'.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 09, 2015 Oct 09, 2015

trace(specialList[0]);

then use the result here specialList.indexOf('result');

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 12, 2015 Oct 12, 2015

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();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 12, 2015 Oct 12, 2015
LATEST

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines