2 Replies Latest reply on Mar 2, 2007 2:26 AM by ctzn99

    Dynamic IDs

    tobrown779
      I need the ability to create an ID on-the-fly. Is this possible in Flex? I'm trying to transition some of my current apps from Ajax to Flex, and this will be devastating blow to my efforts if this isn't possible. Thanks.
        • 1. Re: Dynamic IDs
          tobrown779 Level 1
          Right now I'm kicking my self for even thinking of going this route. Flex...Dynamic....ummm
          • 2. Re: Dynamic IDs
            ctzn99 Level 1
            You can change the ID of any control on the fly if it has an ID already or, if you are creating the control progrmatically and then adding it to a container of some sorts you can set it's ID during creation or change it's ID afterwards.

            I.E.

            var label:Label = new Label();
            label.id = "lblStatus";
            label.text = "Control created.";

            if you wanted to invoke some sort of method belonging to the control in a different routine you could then add the control to an array of DisplayObjects and then search it using the ID (which all DisplayObjects have), then when a match is found cast that particular item in the array to the appropriate type (in this example "Label") then invoke one of the labels methods.

            For example.

            for each (var object:DisplayObject in objectList)
            {
            if(object.id == "lblStatus")
            {
            var label:Label = Label(object);
            Alert.show(label.text);
            // or Alert.show(Label(object).text);
            }
            }