2 Replies Latest reply on May 22, 2009 10:10 PM by Sankar Kethineni

    one ArrayCollection variable in two components

    Sankar Kethineni Level 1

      Hi Friends,

       

      here is  my problem statement.In my application, i have a button and on click of it,opens a popup-window(say FriendsComp) in which i have declared one public arrayCollection variable and it has one more component(say MyFriendsList) included in it. In MyFriendsList component,am displaying the all of my friends with picture and as well as name.you can select the friends by clicking on it and add them item into the array collection which is decalred in FriendsComp and if it is already there then remove it and the selected friends will be displayed in another component.

       

      In my popup-window(FriendsComp),search option is available i .e. you can search for a friend and add to it the same array collection variable and if it is already there then don't add it.

       

      But some how am not able to get it working.So any one can help me on this.

       

      Thanks in advance.

       

       

      here is the code.................

       

      parent component (FriendsComp)

       

      [Bindable] public var selectedFBFrnds:ArrayCollection = new ArrayCollection();         

       

       

      private function onKeyDown(event:KeyboardEvent):void {
                      if (event.keyCode == Keyboard.ENTER) {                   
                          if (selectedFBFrnds.length >= 0 && fbFreindSelectedList.selectedItem != null) {                       
                             
                              if(selectedFBFrnds.contains(fbFreindSelectedList.selectedItem)) {
                                  Alert.show("don't add me");
                              }
                              else {
                                  Alert.show("add");
                                  selectedFBFrnds.addItem(fbFreindSelectedList.selectedItem);
                              }
                          }
                      }
                  }

       

      <comp:MyFriendsList parentRef={this} />

      i have a component for search and that has the keyDown event

       

       

      another component ( MyFriendsList)

       

         here am using the TileList and it has the itemClick event to select the friends

      public var parentref:FriendsComp = null

      private function getSelectedFBFriends(event:Event):void {   
              if (parentRef.selectedFBFrnds.length >=0 && fbFrndsList.selectedItem != null) {
                  if (parentRef.selectedFBFrnds.contains(fbFrndsList.selectedItem)) {
                      Alert.show("if");
                      parentRef.selectedFBFrnds.removeItemAt(parentRef.selectedFBFrnds.getItemIndex(fbFrndsList .selectedItem));
                  }
                  else {
                      Alert.show("else");
                      parentRef.selectedFBFrnds.addItem(fbFrndsList.selectedItem);
                  }           
              }   
      }

        • 1. Re: one ArrayCollection variable in two components
          Gregory Lafrance Level 6

          When you say it is not working, how is it not working?

          • 2. Re: one ArrayCollection variable in two components
            Sankar Kethineni Level 1

            Hi  Greg,

             

              I have forgotten to explain how it is not working and thanks for your reply.

             

                           See my intension is to select friends eithering by clicking on it or through search ( as you type, the relavant names will be populated and press enter).Now, assume that i have selected a friend XXX which will be added to the arrayCollection variable( and if you select the same friend for second time it will be remove from the arrayCollection var. this is working fine for me) and am trying to select the same friend through search and since that friend is already added to that arrayCollection variable it shouldn't be added.But this is adding.

             

              And the vice-versa also not working i.e if you selecte a friend through search and trying to add the same friend by clicking on it.

             

            I hope you understand my problem and let me know if any other information required.

             

             

            Regards

              sankar