2 Replies Latest reply on Dec 5, 2006 11:53 AM by ntsiii

    Programmatically added components - issues with ID

      Hello. I'm developping an application which purposes is to display "x" Tilelists inside a ViewStack.
      I use a loop to create the TileLists, as you can see below :

      for ( i = 0; i < nb_viewstacks; i++) {
      var newTileList:TileList;
      newTileList = new TileList;
      var i_text:String = i.toString();
      newTileList.id = "TL_"+i_text;
      newTileList.width = 435;
      newTileList.height = 310;
      newTileList.horizontalScrollPolicy ='off';
      newTileList.verticalScrollPolicy ='off';
      newTileList.dataProvider = myarray ;
      newTileList.itemRenderer = new ClassFactory(affiche_renderer) ;

      This works fine, it creates as many TileLists as I need. The problem is that I need to create 2 buttons which allow user to change the active Tilelist ("see previous", "see next").

      How can i indicate the ID of the selectedChild in my function dynamically, as I don't know its ID ?? I've tried this :
      click="target_ViewStack.selectedChild= TL_.i_text;"

      Flex returns an "1120: Access of undefined property TL_" error, when compiling the application.

      I guess that's because the TileLists are dynamically created, and don't exist yet when I run the application. Is this problem related to "Event" ?

      Thanks for your help, Garenne.
        • 1. Re: Programmatically added components - issues with ID
          peterent Level 2
          You can keep the TileLists in an Array:

          var mytilelists:Array = new Array();
          for ( i = 0; i < nb_viewstacks; i++) {
          var newTileList:TileList;
          newTileList = new TileList;
          // the rest of your loop

          Then you can access the first TileList as mytilelists[0], then second using [1], etc.

          I notice that you are adding the TileList to a Canvas and not to the ViewStack. So are you really getting what you want?

          Also: if Button 1 is supposed to go to the first child of the ViewStack, you can also do: target_ViewStack.selectedIndex = 0 and if you can use positions, you won't need to remember the TileLists.
          • 2. Re: Programmatically added components - issues with ID
            ntsiii Level 3
            I'll explain about "id" references a little further, as I have come to understand:

            Say you put an id="someValue" into an mxml tag. When the mxml is generated into AS (the first step in compilation), the generator creates an instance variable named "someValue" that contains a reference to the control generated by the tag. This is why you can reference a control by its id.

            When you instantiate controls in code, you have to do this step yourself.