Archive

Posts Tagged ‘viewstack’

Flex 2, Viewstack latency

September 20th, 2007

When using viewstack I notice that it shows to early for me. The mxml page that I want to display is to heavy to create so the page shows up and isn’t completly ready too be shown.

Problem here is that the viewstack has to many private functions so it’s not possible to override the functions needed. This is my solution.

1.) In every mxml to be shown i created build(); and destroy(); functions. These are used to add listeners, set text, remove listeners and so on. I also added a variable :
public var INITIALIZED:Boolean=false;
Then to show that my build () function has run I broadcast an event.
It looks like this;

public var INITIALIZED:Boolean=false;
public function build() : void
{
    this.INITIALIZED = true;
    dispatchEvent(new Event(Page.INITIALIZED));
}
public function destroy() : void
{
    this.INITIALIZED = false;
}

Then I extend the viewstack that the pages lies in. on addChild I added my listener. Override the validateDisplayList to make sure the build function is runned and in the listener I showed the page.

override public function addChild(child:DisplayObject):DisplayObject
{
    child.addEventListener(Page.INITIALIZED, this.pageInitialized);
    return super.addChild(child);
}
 
override public function validateDisplayList():void
{
    super.validateDisplayList();
    var child:Object = Object(getChildAt(selectedIndex));
    if(!child.INITIALIZED)
    {
        child.visible = false;
        child.endEffectsStarted();
        Object(child).build();
    }
}
 
private function pageInitialized(event:Event):void
{
    var child:Container = Container(event.target);
    child.visible = true;
    child.dispatchEvent(new FlexEvent(FlexEvent.SHOW));
}

Flex , , ,