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

Adding to an array

Guest
May 11, 2015 May 11, 2015

There is a textbox for the user to add their name, and 4 seperate ones to add a score per week. How can I make it so that the score is only added to the name specifically "called up". So if I enter the name :

John Smith

Score :

Week 1 : 5

Week 2 : 7

Week 3: 0

Week 4: 10

How can I make it so that the score 22 is only added in John Smith`s name and not the whole employee list?

TOPICS
ActionScript
282
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 ,
May 11, 2015 May 11, 2015

What does an array have to do with the data you are asking about?  You will need to explain how you have this data structured/stored.

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
May 11, 2015 May 11, 2015

Not quite sure i understand your question, but I have a seperate .as file which includes a list of employees, and I call that file up in my main .as file. The user would be adding data to an existing string (the score to the name) or create a new name with the score adding on to it

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 ,
May 11, 2015 May 11, 2015

Yeah, explain how all of that is supposed to work.  Don't forget to include how the array fits in.

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
May 12, 2015 May 12, 2015
LATEST

This is the interface (so far). So they can enter a name and add it to the array and list on the interface with buttons. I am able to do that, what is troubling me is how to add the score to that name (weither it is one that was added at the same time as the score or a name previously entered). What  have so far is the score is added to every name in the string and not the specfic name entered in the textbox. Hope that helps? The code is beneath the interface imge.

EDIT : So I managed to get it so that the score only associates itself with the name entered. But if the name was previously listed, it will add the name again with the score entered, how do I get the score to add to the score currently under that name and not have the name repeat itself twice?

fidelisation.png

package

{

import flash.display.*;

import flash.text.*;

import flash.events.MouseEvent;

public class U1A7_Fidelisation extends MovieClip

{

  // Déclarer un tableau pouvant contenir un nombre indéterminé d'éléments.

  var adherent:Array = new Array();

  // Déclarer une variable pour contenir la liste des noms à afficher.

  var liste:String;

  // Déclarer une variable pour additionner les milles de l'adhérent.

  var totalMille:int = 0;

  var milleSemaine1:int = 0;

  var milleSemaine2:int = 0;

  var milleSemaine3:int = 0;

  var milleSemaine4:int = 0;

  public function U1A7_Fidelisation()

{

  // Ajouter un détecteur d'événement pour réagir à un clic sur btnListe.

  btnListe.addEventListener(MouseEvent.CLICK, lister);

  // Ajouter un détecteur d'événement pour réagir à un clic sur btnTri.

  btnTri.addEventListener(MouseEvent.CLICK, trier);

  // Ajouter un détecteur d'événement pour réagir à un clic sur btnAjout.

  btnAjout.addEventListener(MouseEvent.CLICK, ajouter);

  // Ajouter un détecteur d'événement pour réagir à un clic sur btnSupression.

  btnSuppression.addEventListener(MouseEvent.CLICK, supprimer);

  // Ajouter un détecteur d'événement pour réagir à un clic sur btnSupression.

  btnTotalMille.addEventListener(MouseEvent.CLICK, calculeTotale);

  include "U1A7_Milles.as"

  } // Fin fonction

  function calculeTotale(event:MouseEvent):void

  {

   milleSemaine1 = int(saisieSemaine1.text)

   milleSemaine2 = int(saisieSemaine2.text)

   milleSemaine3 = int(saisieSemaine3.text)

   milleSemaine4 = int(saisieSemaine4.text)

 

   totalMille = milleSemaine1 + milleSemaine2 + milleSemaine3 + milleSemaine4

   trace(totalMille)

  }

  // Fonction pour réagir à un clic sur bouton btnListe.

  function lister(event:MouseEvent):void

  {

  liste="";

  for (var i=0; i<adherent.length; i++)

  {

  liste = liste + (""+ adherent + " " + totalMille + "\n");

  }

  affichage.text = liste;

 

  } // Fin lister

  // Fonction pour réagir à un clic sur bouton btnTri.

  function trier(event:MouseEvent):void

{

  // Trier les éléments du tableau par ordre alphabétique.

  adherent.sort();

  } // Fin trier

  // Fonction pour réagir à un clic sur bouton btnAjout.

  function ajouter(event:MouseEvent):void

{

  // Ajouter un nouvel élève au tableau.

  adherent.push(saisieNom.text + " " + saisiePrenom.text);

  } // Fin ajouter

  // Fonction pour réagir à un clic sur bouton btnSuppression.

  function supprimer(event:MouseEvent):void

{

  var indiceAdherent:int;

  indiceAdherent =(adherent.indexOf(saisieNom.text));

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

  if (indiceAdherent != -1)

  {

  for (var i=indiceAdherent; i <adherent.length; i++)

  {

  adherent = adherent[i+1];

  }

  adherent.pop();

  }

  } // Fin supprimer

} // Fin classe

}  // Fin paquetage

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