8 Replies Latest reply on Feb 23, 2007 9:32 AM by darko.romanov

    Reaching a component in a TileList

    darko.romanov
      Hi all, I have a TileList with a custom component:

      <mx:TileList x="0" y="0" id="tl_acc_pictures" dataProvider="{XMLAccessoryImagesList.source}" width="100%" height="100%">
      <mx:itemRenderer>
      <mx:Component>
      <aocc:customaccessoryimagetile _sessionid="{parentApplication._sessionid}" />
      </mx:Component>
      </mx:itemRenderer>
      </mx:TileList>


      quite simple. customaccessoryimagetile contanins a CheckBox that, when clicked, should de-select all other customaccessoryimagetile CheckBoxes. But how do I reach other customaccessoryimagetile ?

      I know this is about a very discussed issue, but I really didn't find anything that could help me.
      d
        • 1. Re: Reaching a component in a TileList
          darko.romanov Level 1
          update:

          I tried adding an event listener to my customaccessoryimagetile and an event dispatcher too, so, when I click the customaccessoryimagetile CheckBok, it throw the event, but it's trapped only by the customaccessoryimagetile itself and the TileList and NOT by other customaccessoryimagetile.

          Have any idea about how to make other customaccessoryimagetile trap events?

          d
          • 2. Re: Reaching a component in a TileList
            peterent Level 2
            I have a couple of thoughts on this. First, if you have a CheckBox that when clicked, de-selects all the other check boxes, then wouldn't a RadioButton make more sense? And if you can use RadioButtons, you can create a RadioButtonGroup to which your itemRenderers belong and then they would automatically de-select.

            Second, if you need to use a CheckBox, then you could implement something similar to a RadioButtonGroup. Each itemRenderer could register itself with this group. Selecting one could invoke a function in this group which would, in turn, invoke a method in every registered renderer. For example, if you make an interface, say ICheckBoxGroup which has a function called deselect(), each itemRenderer then implements the interface and defines the function. The group then loops through all of the registered members and invokes this function.

            The thing about itemRenderers is that you aren't supposed to be able to get hold of them. They are ephemeral. They can be re-used. An itemRenderer should only get its data from the row of the dataProvider.

            Knowing that, you could add a field to each record of the dataProvider and when an itemRenderer is selected, go through the dataProvider and un-set the field. As you do that, use the dataProvider's itemUpdated() function, passing in the item and name of the field you just changed. This will cause the itemRenderers for that field to be invalidated and their updateDisplayList functions will get called.
            • 3. Re: Reaching a component in a TileList
              darko.romanov Level 1
              Hi, I tried with radiobuttongroup but without success.

              I think your last suggestion wouldn't apply to my case, as I have a TileList, not a DataGrid.

              BTW, I've finally used the method "described" here http://www.macmartine.com/blog/2006/03/binding_custom_objects_to_tile.html

              and it works but I don't know how to call my customaccessoryimagetile using IUID... how can I reach an Object, modify its properties, using his IUID?

              (for reference about my code see this http://www.macmartine.com/blog/flexsource/2.0/beta2/2006_03_16/Main.mxml.html and http://www.macmartine.com/blog/flexsource/2.0/beta2/2006_03_16
              • 4. Re: Reaching a component in a TileList
                peterent Level 2
                Whether it is a TileList or a DataGrid or a plain List, it is all the same when it comes to itemRenderers.

                What's being said in in Mac Martine's site is OK, but if we decide to change how we identifiy itemRenderers, then you are out of luck. The best-practice solution is the one where you implement your own group item and use an interface.
                • 5. Re: Reaching a component in a TileList
                  darko.romanov Level 1
                  Ok, I'm going to see strawberry fields instead data fields... :-)

                  I'm trying to use your method, same described here http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Live Docs_Book_Parts&file=about_dataproviders_057_11.html

                  but I can't make it works! i can't understand what collection it means with collectionOfThoseClasses in:

                  myCollection.itemUpdated(collectionOfThoseClasses.getItemAt(0));

                  (from the page of the link)

                  myCollection is the dataProvider of the TileList, ok, but collectionOfThoseClasses what would it be?

                  I did:

                  for(var i:int = 0; i<tl_objet_images.dataProvider.length; i++) {
                  objectImages.getItemAt(i).defaultimage = "N";
                  objectImages.getItemAt(i).url = "";
                  objectImages.itemUpdated(objectImages.getItemAt(i));
                  }

                  where objectImages is my dataProvider and when defaultimage == "N" the CheckBox of the itemRenderer is not selected. But this check is done on creationComplete of the itemRenderer, so it won't update its CheckBox...

                  I'd like to reach directly the CheckBox, with something like:

                  collection.object.checkboxId.selected = true|false;

                  is it possible? Or it would be ok also if I could regenerate the itemRenderers...
                  • 6. Re: Reaching a component in a TileList
                    darko.romanov Level 1
                    quote:

                    Originally posted by: peterent
                    Second, if you need to use a CheckBox, then you could implement something similar to a RadioButtonGroup. Each itemRenderer could register itself with this group. Selecting one could invoke a function in this group which would, in turn, invoke a method in every registered renderer. For example, if you make an interface, say ICheckBoxGroup which has a function called deselect(), each itemRenderer then implements the interface and defines the function. The group then loops through all of the registered members and invokes this function.



                    I don't have strong knowledge about interfaces (generally in OOP) so.. may you write a pseudo-code of this?

                    • 7. Re: Reaching a component in a TileList
                      peterent Level 2
                      OK. Create ICheckBoxGroupMember.as:

                      package {
                      import mx.core.IUIComponent;
                      public interface ICheckBoxGroupMember {
                      function deselect( o:IUIComponent ) : void;
                      function select( o:IUIComponent ):void;
                      }

                      Interfaces do not use public, private, etc. and the functions have no content.

                      Create CheckBoxGroup.as:
                      package {
                      import mx.core.UIComponent;
                      public class CheckBoxGroup {
                      static private var members:Array;
                      static public function registerMember( o:UIComponent ) : void {
                      members.push(o);
                      }
                      static public function select( o:UIComponent, selected:Boolean ) : void
                      {
                      for(var j:int=0; j < members.length; j++) {
                      if( selected ) (members[j] as ICheckBoxGroupMember).select(o);
                      else (members[j] as ICheckBoxGroupMember).deselect(o);
                      }
                      }
                      } // end of class
                      } // end of package and file

                      The CheckBoxGroup class has static members so it is easy to call from anywhere as long you import its definition (or it is in the same package).

                      Your itemRenderer should implement ICheckBoxGroupMember:

                      <mx:whateveryourroottagis implements="ICheckBoxGroupMember" initialize=register()>
                      <mx:Script><![CDATA[
                      private function register() : void {
                      CheckBoxGroup.register(this);
                      }
                      public function select( o:UIComponent ) : void {
                      if( this != o ) dowhateveritisyoudotomakeyouritemselected;
                      }
                      public function deselect( o:UIComponent ) : void {
                      if( this != o ) dowhateveritisyoudotomakeyouritemdeselected;
                      }

                      In your itemRenderer, when you find it has been selected by the user, call CheckBoxGroup.select(this,false) so all of the others will be deselected. Or when the item is unchecked, call CheckBoxGroup.select(this,true) so all of the others become selected (that's assuming you want to do that).
                      • 8. Re: Reaching a component in a TileList
                        darko.romanov Level 1
                        wow it works! thanks a lot