R – Flex viewstack keeps redrawing invisible child, how to fix

apache-flexmemoryviewstack

The situation: I've got a ViewStack with 2 children (both of type Panel).
The application starts with child 1 as the SelectedChild.

With a click on a button, child 2 is the SelectedChild. After that, I return to child 1 being the SelectedChild.

When I click Show Redraw Regions in the Flash Player, I can see child 2 being redrawn the whole time (i've got some moving objects in child 2). How can I prevent this from happening? Or can this only be done with actually removing the invisible (in this case child 2) child?

Why I want to achieve this? Child 2 will contain pretty much data (flv's, images, etc.) and when it's being cached like what happens now, it will slow down my application.

Best Answer

A major source of inefficiency in Flash can come from invisible objects on your display list. Not only do they continue to cause redraw region refreshes ("red rectangles"), they impose CPU penalties on Flash processing whenever the player needs to traverse the display list tree. Mouseovers are notably more expensive, even if you don't have any MouseEvent listeners, when the display list is larger. Any display list containing more than a couple thousand objects can start to feel the pain.

Long story short, sometimes performance dictates that you write your own "visibility manager" to swap objects in and out of the parent hierarchy as an alternative to toggling DisplayObject.visible.

Related Topic