2 Replies Latest reply on Sep 23, 2010 6:46 AM by rogerioharuo

    [Help] Create dinamically components and its id

    rogerioharuo

      Hello guys.

      I need a help

      I know it sounds weird from the title above but I have been struggling to find a better solution but can´t figure it out.

      I have searched through internet but couldn´t find a solution for my problem.

       

      Here is what I have to do.

      I need to create an agenda. Every single cell has to accept an new event or delete an existing event

      The idea is to show all 365 days of the year. It´s important and clearer to the user.

       

      I´ve tried to use the <mx:Repeater> to reproduce a custom component 365 times. It was successfull but I can´t figure out a way to access those components to change its properties.

      As some of them may have an apointment and others not.

      <mx:HBox horizontalGap="0">

      <mx:Repeater id="monthRepeater">

      <mx:VBox verticalGap="0">

      <mx:Box id="mes_box" borderColor="#000000"

      borderStyle="solid"

      borderThickness="0.5"

      width="80">

      <mx:LinkButton label="{monthRepeater.currentItem.month}" fontStyle="normal" fontWeight="normal"/>

      </mx:Box>

      <mx:VBox verticalGap="0">

      <mx:Repeater id="daysRepeater">

      <visao:CaixaDia id="day_caixaDia" linktexto="{daysRepeater.currentItem.day}" labeltexto="{daysRepeater.currentIndex}" />

      </mx:Repeater>

      </mx:VBox>

      </mx:VBox>

      </mx:Repeater>

      </mx:HBox>

       

      Is there a way to use <mx:Repeater> and create dinamically IDs for those components?

       

      Thanks

        • 1. Re: [Help] Create dinamically components and its id
          Gregory Lafrance Level 6

          You can access the objects created by a repeater as if the id were an array, as in the following sample code:

           

          <?xml version="1.0"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
            <mx:Script>
              <![CDATA[
                import mx.collections.ArrayCollection;
                import mx.containers.VBox;
                import mx.controls.Label;
                
                [Bindable] private var ac:ArrayCollection = new ArrayCollection([
                  {vb_color: 0x000000, lb_text: "Black"},
                  {vb_color: 0xFFFFFF, lb_text: "White"},
                  {vb_color: 0xCCCCCC, lb_text: "Gray"},
                  {vb_color: 0xFF0000, lb_text: "Red"},
                  {vb_color: 0x00FF00, lb_text: "Green"},
                  {vb_color: 0x0000FF, lb_text: "Blue"}
                ]);
                private function changeUI():void{
                  for each(var vb:VBox in topVB){
                    vb.setStyle("backgroundColor", 0xFFFFFF);
                  }
                  for each(var lbl:Label in myLabel){
                    lbl.text = "changed";
                  }
                }
              ]]>
            </mx:Script>
            <mx:Button label="Change UI" click="changeUI();"/>
            <mx:Repeater id="rp" dataProvider="{ac}">
              <mx:VBox id="topVB" backgroundColor="{rp.currentItem.vb_color}">
                <mx:Label id="myLabel" text="{rp.currentItem.lb_text}"/>
              </mx:VBox>
            </mx:Repeater>
          </mx:Application>
          
          


          If this post answers your question or helps, please mark it as such.


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          Flex Training and Support Services

          • 2. Re: [Help] Create dinamically components and its id
            rogerioharuo Level 1

            Thanks a lot.

            It solved my problem and saved me a lot of time.

            I have been thinking of a work around but couldn´t find a good one.

            I have almost created 365 instances of the same object.