Skip to main content
Known Participant
March 28, 2011
Question

Best practices on when mxml is fully created

  • March 28, 2011
  • 1 reply
  • 689 views

Basically this problem occurs when I use CreationComplete to init() my controller etc.

I find myself digging around in Debug mode trying to find things like the stage.stageWidth which hasn't really fully be created and for all intesive purposes creation is not complete/!

I'm thinking am I missed that it's creationCompleted with a "D" at the end is another place where it's really completed and not still completeing.

It seems like an inhereit problem with the flash frame cycling, but alas we can't even have one frame wrong. I'm guessing people turn visibility false and launch a 10 micro second timer to call the real init so one frame later the MobileApplication spark View (in this observence) has actually completed the creation process.

I suppose sometime this happens worse with my SplashScreen (initial view) in trying to find the screen size and otherthings.

It really seems unknownable and possible near random that a particular thing may or may not be properly initialized when I need access to it.

Maybe someone can post a refresher course link for (advanced noops) moderate developers to better understand the complex in's and out's of frame cycles and initializations on start up etc.

I think when I dig around I'll find something like stage.fullScreenWidth not 'screenWidth' or the actual 'width', is the only one not 0 zero that has the value I need.

I am certain it's condusing and difficult for all developers, and as a developer I tend to think I wouldn't release it in that state, it's wrong. things should be initialized when I get to my function for creationComplete. If you must consider added after the fact a creationCompleted (with 'ed = past-tense), although that would be slightly confusing and no one would likely ever use creationComplete ever again.

This topic has been closed for replies.

1 reply

as4moreAuthor
Known Participant
March 30, 2011

I found a link with the R&D results...

http://blog.anselmbradford.com/2008/08/22/after-creationcomplete-a-flex-components-stage-property-is-what-null/

Looks like it depends...

First there is also an addedToStage (ATS) to compliment creationComplete (CC), also note applicationComplete (AC)

If you're looking from MXML it's CC before ATS, and then potentially AP

if you're looking from  AS3   it's ATS before CC

Anyway I tried AddedToStage and it wasn't nessecarily that stage wasn't null yet?! that just does not seem right to me.

With various hacks around the confusion I have a mixed bag of them. Honestly I'm not really sure, so again that is a great example of why I heard (the other day to my initial shock) people think programming in Flash/AS3 is difficult (I'll add powerful so maybe not as hard to do more.)

Any further clarity or others experience, suggestions, here would be great, thanks.

Dispite the article saying use addedToStage to get stage to not be null, my experience is it's not always availible. Probably during initial application launch so I'm still launching timers in the background to get past a frame or two until the stage is no longer null and then clean up the mess and move forward with the apps life-cycle.

as4moreAuthor
Known Participant
March 30, 2011

It's worth noting there is similar quirkyness when exiting.

It's suggested you sent an exting event your self when you call exit incase you halt it for whatever reason.

            var exitingEvent:Event = new Event(Event.EXITING, false, true);
            nativeApp.dispatchEvent(exitingEvent);
            if (!exitingEvent.isDefaultPrevented()) {
                nativeApp.exit();
            }

You can add an Exiting listener too to the NativeApplication of course.

Further with MobileApplication there is onActiviationApp and more in this situation onDeactivateApp (& view's too).

If you close the window in AIR you get deactivateApp befire the exiting event...

but you call your exiting event you get that before the deactivateApp event.

So I guess the lesson is either it's messed up and needs serious consideration and fixing for the sake of easier programming or it's all jumbled and messed for a very good reason so deal with it. Not that I precieve particular issues with exiting in my current situation, rather more with the creationComplete and addedToStage stuff.

Still awareness of your problems is the first step to recovery, so take note of the mighty jumbolia of events in AS3 and Mobile AIR and variations, etc.

Oh I've also notice there is the option to catch a window Event.CLOSING at the bottom of this page...

http://livedocs.adobe.com/flex/3/html/help.html?content=app_launch_1.html