This content has been marked as final. Show 5 replies
Okay I think I've added the row to the grid correctly by using selectedChild.
But now how do you add the items to the rows??
If you're going to need to refer to child components after adding them to the parent, it's easiest to simply keep a reference to them. Instead of using a local variable "page", declare a property in whatever class you're in and use that. eg:
private var myGrid: Grid;
//In some method:
myGrid = new Grid();
In another method, you can use myGrid to get at the grid.
As for your grid question, I really think you need to read over the documentation about data-driven controls (including the DataGrid) and learn about adding columns and setting the dataprovider.
Thanks very much for your reply. I can see that having the component defined as a local variable is actually one of the problems.
What I should have realized, but didn't was that Grid is the old DataGrid component. Using the dataProvider for this is too restrictive as I need each cell to contain data from several different sources and separately addressable.
I think what I need is the VBox and HBox containers with Tile containers inside them and Text components inside the Tiles.
I wish there were some AS examples using components in the Help files, but I can't find much. It seems almost exclusively mxml.
Am I right in thinking that mxml cannot handle dynamic layouts i.e. where the contents of the parameters are variables?
If you mean to you want to create components at runtime, then that's what you were doing with "new" and "addChild". They're pretty straightforward to use, are they not? You can simply add Text components to a TileList and then add that to a VBox, etc.
Yes, it's easy and I now have it all working.
Whereas in fact the way to do it is to add all tiles to an HBox, then add each HBox (which then comes with its children automatically) to the VBox and so on and then you don't need to know how to refer to them from the top down. And in fact you can add them in any order you like as long as you just add the child to its parent directly instead of to its whole chain of parents.
But I would say that its not easy to guess that this is the way to do it if there are no examples and you have no prior experience.
Thanks very much for all your help. It is much appreciated.