A loop like that is doomed because the index of the children change as you
remove each child. Loops to removeall typically look like:
I think you really mean
I hate the while short form. I'd rather write the more explanatory version so there's no doubt that everyone can follow the code.
I know it how to remove all children using index 0.
But this is the case for application container (the first mxml file).
There is something in the rawChildren that I don't want to remove like the "backgroundMask" & "border".
These names are what I got from a loop scanning items in rawChildren.
I don't want to remove these component (created by default) in the application container
because if removing them, I can't catch the mouse click event on the background.
You guys please help, I need to remove all children except those mentioned above...
I don't understand the scenario. Can you give a more detailed description?
Most of the time you don't want to remove rawChildren, so you'd run a
similar loop on the current children
Hi Flex harUI,
You may notice this situation, before and after running this code on application container
(Flex Builder 3)
while(this.rawChildren.numChildren > 0)
There an image background in the application container,
the gradient of the blue image can be seen, not so clearl but visible.
After running the code above:
The background of the application container
is a plain blue background.
Try to catch the MouseEvent.CLICK on the application background
after running the code, I (tested) and believe the event can't be
caught; because the background is now transparent
(the background image already removed by the code)
ActionScript seems to ignore transparent pixels.
It is rare to use rawChildren to remove everything. The MXML tags you added
to your application are in the regular children array. RawChildren contains
chrome and other stuff you probably don't want to remove.
Maybe describe a scenario and explain what your goal is.
The scenario is like this:
Panels (a few)
Panels add Loaders (swfs) to application but the application doesn't know
(each panel has a property called 'application':mx.core.Application,
panels use this property to add components to rawChildren)
Application has to clear the work space,
and it can't seem to know those Loaders (swfs) loaded by the Panels
which are children of Application, it can only clear the panels.
Quite a confusing case
I would question the design. Adding stuff to rawChildren is not
recommended. If you have to do so, you will need a way to figure out what
got added. Maybe remember the number of things in rawChildren.
Anyway, I try to save the list of things added, so when I need to remove, I would know what to remove.