IdleSun's Weblog

October 9, 2008

Flex – When is the stage available?

Filed under: Flex — idlesun @ 6:21 pm

I wanted to capture all the key strokes and handle them once my Flex app is launched. I found that I need to add a handler to the stage and I tried with the creationComplete event of my Application. However, I couldn’t get what I want because the stage variable was STILL null. And then after a while I found that there is another event right after creationComplete. That is applicationComplete. Voila! I could access the stage and got what I wanted.

<mx:Application applicationComplete="onAppComplete()">
    private function onAppComplete():void {
      if (this.stage != null)
      stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
    private function onKeyUp(event:KeyboardEvent):void	{
      // handle key strokes

By the way, I couldn’t resolve my problem without this: Flex Instantiation Life Cycle and Event Flow. Thanks Ted!


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a free website or blog at

%d bloggers like this: