2 Replies Latest reply on Nov 1, 2010 5:22 AM by actionscript2n3

    Assign dynamic id to flex components




      Is it possible to assign dynamic id to flex components like:


      var dId:String = "myImage";


      <mx:Image id="{dId}" />


      I am trying to do it in an itemRenderer, the code is as under:
                           <mx:Image id="{data.id.toString()}"


      and the error is:
      '{data.id.toString()}' is not a valid identifier.


      Thanks for any help

        • 1. Re: Assign dynamic id to flex components
          BhaskerChari Level 4



          You can dynamically set id for a component which is created dynamically in ActionScript but in MXML it is not possible the way you assigned an id dynamically bindable to a variable.


          Why do u need an id in your case....?? Whats the problem do u face with out giving an id..??





          • 2. Re: Assign dynamic id to flex components
            actionscript2n3 Level 1

            Thanks Bhasker,


            I am using an Tile List component and each item represents an tool say item 1 represents text tool and item 2 represents image upload tool. As I am new to flex so I am not very rich in using flex components. My problem is that each item of <mx:TileList /> needs to be draggable and I have to show relative tool where it gets dropped, say my tilelist represents only 2 items 1: text tool(image) 2: image upload tool(image)

            Now I am using above itemRenderer code to add each item based on arraycollection.


            This line:

            mouseDown="outerDocument.imageMouseDownHandler(event)" adds mouseDown event to image component added then I am using DragSource and DragManager to add drag feature. But the problem is that how to identify each item after drop. I have to show tool added based on the item dropped.