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

How to add an element to an array, then be able to remove it specifically

Guest
Apr 03, 2015 Apr 03, 2015

So i have a list of numbers. The user is able to then add numbers to that list. I have a button which allows the user to remove any number of their choice by typing that number in a textbox. For some reason the numbers that the user add to the list will not dissapear when chosen whereas the original numbers go away no problem.

The name of the array itself is mesEntiers and the name of the texbox is : IntegersIn_txt

Here is the code :

function supprimer(event:MouseEvent):void

  {

  var indiceChiffre:int;

  indiceChiffre =(mesEntiers.indexOf(IntegersIn_txt.text));

  // La méthode indexOf renvoie l'indice d'un élément ou -1 si non trouvé.

  trace("testBtn")

  if (indiceChiffre != -1)

  {

  for (var i=indiceChiffre; i <mesEntiers.length; i++)

  {

  mesEntiers = mesEntiers[i+1];

  trace("test")

  }

  mesEntiers.pop();

  }

  } // Fin fonction supprimer.

TOPICS
ActionScript
230
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

LEGEND , Apr 03, 2015 Apr 03, 2015

Two things I can think of (I ran a small test)...

1) Make sure your textfield is a single line, not multiline...  multilines end up with extra stuff in them that you can't see.

2) Convert the text into a number unless the array is holding strings...  indiceChiffre =(mesEntiers.indexOf(Number(IntegersIn_txt.text)));

Translate
LEGEND ,
Apr 03, 2015 Apr 03, 2015

Two things I can think of (I ran a small test)...

1) Make sure your textfield is a single line, not multiline...  multilines end up with extra stuff in them that you can't see.

2) Convert the text into a number unless the array is holding strings...  indiceChiffre =(mesEntiers.indexOf(Number(IntegersIn_txt.text)));

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
Guest
Apr 03, 2015 Apr 03, 2015

Awesome! I made the change #2 and converted them into Numbers and it works like a charm now. 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
LEGEND ,
Apr 03, 2015 Apr 03, 2015
LATEST

You're welcome

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