tags:

views:

59

answers:

1

Hi there,

I'm having a problem similar to http://stackoverflow.com/questions/1410398/flex-dialog-not-display-immediately . Code follows:

private function saveBitmap(event:ContextMenuEvent):void
{
    loadingScreen.visible = true;
    loadingScreen.appLoadingText.text = "Preparing bitmap...";
    addChild(loadingScreen);

    validateNow();

    var bmpd:BitmapData = new BitmapData(canv.width, canv.height);
    bmpd.draw(canv);

    var fr:FileReference = new FileReference();
    fr.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, removeLoadingScreen);
    fr.addEventListener(Event.CANCEL, removeLoadingScreen);
    var png:PNGEncoder = new PNGEncoder();
    var iba:ByteArray = png.encode(bmpd);
    fr.save(iba, "export.png"); 
}

Basically, bmpd.draw and/or png.encode are dog slow, so I'd like to have a nice "please hold while we prepare your png" dialog to appear. I can't use callLater() because of the FileReference.

And just for good measure, the loading screen appears at the same time the save dialog appears from the call to fr.save().

Any ideas?

Cheers!

A: 

You're adding the child in this function. Are you doing any other work to the loadingScreen, such as sizing it? Or positioning it? Most commonly this is done in updateDisplayList(). What container are you using?

Are you sure the Z-order of your two children is correct? You can swap children with the swapChildren method

www.Flextras.com
loadingScreen is sized automatically to 100% on both width and height in the XML, I would've hoped this would be done when I call validateNow().I tried earlier keeping loadingCanvas in this object (which is a subclass of Canvas) and just flicking the visibility, but it still didn't appear.I'm assuming the z-order is correct because the loadingScreen does eventually appear, but not until PNGEncoder is finished.
Andrew
Did you mean XML or MXML? IF you create the component in MXML, you should not be using the addChild() method; because the Flex compiler does magic to turn MXML into ActionSCript which includes adding all children to the their appropriate container. validateNow() should force updateDisplayList() to run. But, does the container you're adding your loading screen to automatically size and position children? I think you need to share more code.
www.Flextras.com
I did mean MXML, sorry. I'm not quite sure how much code you'll be needing, so have it all:http://pubmap.svn.sourceforge.net/viewvc/pubmap/trunk/pubmap/I should add, the code above is in viewport/common.as and loading screen is viewport/LoadingScreen.mxmlThanks for your help so far.
Andrew
I need just enough code so that I can copy and paste into a new application file and it will demonstrate the issue you are having; no more no less. Sorry, I don't have time to "reverse engineer" your whole project to try to diagnose this issue.
www.Flextras.com