0 Replies Latest reply on May 28, 2008 12:29 AM by thush_k

    Change style of dynamically-created button from another button click

      Hi all,

      I've been working on a small project at home, learning Flex and Actionscript as I go (it is great, BTW) and have hit a block.

      I am building a screen with nested containers (HBox, VBox, Tile, etc) eventually holding a number of dynamically-created buttons. This is all generated from an XML data file using For loops. Each button is assigned a unique ID.

      My problem is that I have a set of buttons in an Accordion component. Each Accordion button relates to a dynamically-created button already on screen. So, "Step 1" on the Accordion may relate to "Component 5". This info is held as a String in the .data of the Step button. If a user clicks on the "Step 1" button, I want to change the style of "Component 5", so I need to be able to reference those buttons based on the String from the XML data on Step 1.

      I have tried using the normal setStyle, but that doesn't seem to work as I can't convert the String representation of "Component 5" to the actual dynamically-created "Component 5" button.

      So my question to you fine people is, " How do I change a dynamically-created button from another given only a String representing the button ID?".

      Hopefully, there is a simple way to do this (without having to traverse some component tree). Any help would be much appreciated to a new learner to Flex. If you need any more info about the problem, please let me know.



      Edit: I think the answer may be in this thread here. This states to use an associative array to hold the IDs of the components during creation time and to use the array to reference them later. I will try that and see if it works. Fingers crossed!

      Edit 2: I've cracked it! Firstly, I used a dictionary to hold the array of objects. This used the Dictionary package (imported) and the creation of the dictionary object.

      Then I added my objects to the dictionary during their creation.

      Finally, I reference the buttons using the dictionary object based on a known ID string.