This content has been marked as final. Show 5 replies
What are you trying to accomplish? If you have a component (say a VBox) with id="box" and inside of it you have a Button with id="mybutton", then you can get the Button via box.mybutton.
This flex app is almost entirely Actionscript, and is has several dynamically-generated panel objects, each with it's own set of nested children. Among those children is some checkboxes. Now, when an action is performed in one panel, I want to find a checkbox in one of the other panels and enable/disable.
Maybe I'm missing something here (usually the case), but my experience is that when the id or name of an object is dynamically generated in an class, rather than in a repeater in the mxml, you can't retrieve that element by simpley calling box.mybutton, but you have to walk the tree up and down, looking for that named or id'd object. I sure hope I'm wrong, but I will play again with the guidance you have sent.
Did I say thank you for replying? Thank you for replying.
If you have ActionScript code that creates a component you could assign it an id and keep a map of ids-to-components in the code. For example:
var b:Button = new Button();
b.id = "helpButton";
var map:Object = new Object();
map["helpButton"] = b;
map["choiceCombo"] = c;
Now when you want a specific control and know its id, you can get it through the map. If all of your components follow this pattern you should be able to get a component very quickly.
I very much appreciate your help.
Your approach of mapping ids makes sense. I had also thought of storing the entire name path from the parentApplication to the lowest component on the tree for each component, and using string manipulation and a series of getChildByName() calls.
But here's the rub. In ActionScript, it looks like ids assigned dynamically in an class are treated differently than ids created in mxml. When I attempt to call an id in ActionScript that is created dynamically in a class, I get an undefined property error. For example, the class creates a CheckBox:
var paperAddCheckBox:CheckBox = new CheckBox();
paperAddCheckBox.id = "add" + paperId;
paperAddCheckBox.x = 12;
paperAddCheckBox.y = 27;
And the chekcbox is then added to the the panel or what have you. Later, in a function I want to find this chekcbox and perform some action on it, like set enabled = true or false. To test whether I can actually get to the checkbox, by saying something like:
I get the following error (using sdk. compiling on the command line):
Error: Access of undefined property add662
So, I have a feeling I am being dense, and am missing something obvious that would allow me to access this component by id. I am poised to write a recursive function that will allow me to find any element in an application by id or name, but if this functionality is built into Flex, I would be dancing in the streets. Completely dressed. As a favor to my neighbors, who have had enough of my foolishness.
Thanks so much,
Oh my hat. I get it. Of course, you call map["helpButton"].myProperty. And that works.
You have no idea how much that helps. Should have thought of that myself, blah blah blah.
Have a blessed day, Peter.