0 Replies Latest reply on Feb 23, 2011 12:02 PM by jlanpheer

    Comparing String to Array Collection value syntax.

    jlanpheer

      Hi-

       

      I have the created the following function which compiles but does not behave as i expect it to, and i assume its a basic case of not comparing what i THINK that i am comparing.....    Basically, i am passing in a string, comparing the string to several possible values stored in Arrays, and if a match is found, pushing the matching Array  (and possibly others) into an ArrayCollection (which becomes the datasource of a ComboBox list later).

       

      private function createMatchIndList(valueToMatch:String):ArrayCollection {
              var tempMatchList:ArrayCollection = new ArrayCollection();   
              const RED_COLOR:Array               = new Array ([{label:"Red",data:"R"}]);
              const GREEN_COLOR:Array          = new Array ([{label:"Green",data:"G"}]);
              const BROWN_COLOR:Array         = new Array ([{label:"Brown",data:"B"}]);
             
                 if (valueToMatch == RED_COLOR[0].data) {
                          tempMatchList.addItem(RED_COLOR);
                          tempMatchList.addItem(GREEN_COLOR);
                          tempMatchList.addItem(BROWN_COLOR);
                 }
                  else if (existingMatchInd == GREEN_COLOR[0].data) {
                       tempMatchList.addItem(GREEN_COLOR);
                        tempMatchList.addItem(BROWN_COLOR);
                }
                  else if (existingMatchInd == BROWN_COLOR[0].data) {
                        tempMatchList.addItem(BROWN_COLOR);
                }


              return tempMatchList;
          }

       

      The problem is that if i pass an "R" into this function, it passes straight thru the IF statement "if (valueToMatch == RED_COLOR[0].data" and ends up dropping all the way out and not adding any of the arrays to my ArrayCollection for population later.  What (probably) OBVIOUS mistake have i made?

      cheers,

      Jim.