06-28-2011 04:21 PM
maybe I can't think of proper question, but I can't find anything on this.
I have created a custom component by extending UIComponent. Inside I have Bitmap, TextField, Shape. For now width is fixed.
Now, I would like my component to always take 100% width of Container that I put it in, and based on width calculate height. I'd like everything to stay same size (ie. no Bitmap scaling), except that width of TextField and Shape should be adjusted - depending on parent Container width.
Should I add some listeners to parent, or override my component methods? I'm totally lost here.
Solved! Go to Solution.
06-28-2011 10:12 PM
I'm not sure what the best way to go about this would be. Certainly, you could listen for an ADDED_TO_STAGE event and size the objects accordingly, but this way would not be able to automatically resize if the parent changed sizes.
I suppose you could do a quick check on the ENTER_FRAME event to determine if the parent changed sizes and resize accordingly.
Anyone else have an opinion?
06-29-2011 04:29 AM
Thanks for suggestion.
My structure is like this: ScrollPane ( Container ( N*MyComponent) )
For now whenever size of ScrollPane / Container changes, I itereate over it's children and if it's my component I call MyComponent.onResize() method. But this doesn't feel correct.
06-29-2011 06:05 AM
Setup a custom event in the scroll pane, and the Container and bubble the event through to your components.
i.e. the scrollpane triggers your custom event to the container custom event which triggers the event to your custom components.
06-29-2011 06:01 PM
Thanks. Just to be sure, when you write "Setup a custom event in the scroll pane, and the Container" you mean that I have to extend them and add dispatchEvent(...) where necessary, right?
06-30-2011 05:34 AM
yes, this way then only the components you wish to resize do, and you dont need to itterate overthem.