6 Replies Latest reply on Jan 2, 2007 5:20 AM by moyosaned

    Repeater Component:  Dynamically creating components based on data type

    web_dsnr
      Dynamically creating components based on data type
      You can use a Repeater component to dynamically create different types of components for specific items in a set of data. A Repeater component broadcasts a repeat event as it executes, and this event is broadcast after the currentIndex and currentItem properties are set. You can call an event handler function on the repeat event, and dynamically create different types of components based on the individual data items.
      <mx:Script>
      <![CDATA[
      private function repeatHandler(event:FlexEvent):void
      {
      var _currentItem:String = new String(event.currentTarget.currentItem.@data);
      var _currentI:int = new int(event.currentTarget.currentIndex);

      switch(_currentItem)
      {
      case "home":
      var myComponent:Button = new Button();
      myComponent.label = event.currentTarget.currentItem.@label;
      addChild(myComponent);
      myComponent.x = 0;
      myComponent.y = 50 * _currentI;
      break;
      case "features":
      Alert.show(_currentItem);
      break;
      default:
      trace("Out of range");
      }

      }
      ]]>
      </mx:Script>

      <mx:TabNavigator id="_1" width="100%" height="100%">
      <mx:Repeater id="rp1" dataProvider="{prjXMLList}">
      <mx:Canvas id="c1" label="{rp1.currentItem.@label}" width="100%" height="100%">
      <mx:TabNavigator id="menu" width="100%" height="100%" left="2" right="2" top="5" bottom="2">
      <mx:Repeater id="rp2" dataProvider="{rp1.currentItem.menu}" repeat="repeatHandler(event)">


      <!-- The Canvas below should be replaced by the custom components-->

      <mx:Canvas label="{rp2.currentItem.@label}" width="100%" height="100%" backgroundColor="{rp2.currentItem.@color}">


      </mx:Canvas>
      </mx:Repeater>
      </mx:TabNavigator>
      </mx:Canvas>
      </mx:Repeater>
      </mx:TabNavigator>


      Yes this works but the repeater is nested inside another component but when the components are created it is not nested inside the one it should be.