Mar 5 2007

My favorite Flex code

Posted by Joe Rinehart at 10:48 AM
12 comments
- Categories: Flex

I've typed this exact line of code a few times, and it cracks me up each time. Just thought I'd share...it's nothing important.

var application:Application = Application.application as
Application;

That is all.

Comments

DannyT

DannyT wrote on 03/05/07 11:33 AM

Yep, that just made me giggle... i've no idea why!?
Keith Peters

Keith Peters wrote on 03/05/07 11:52 AM

That's beautiful stuff right there.
Joe Rinehart

Joe Rinehart wrote on 03/05/07 12:09 PM

Try saying it ten times out loud without a coworker throwing something at you :)
Critter

Critter wrote on 03/05/07 1:10 PM

um... you people /really/ should get out more.


no, seriously.
Keith Peters

Keith Peters wrote on 03/05/07 1:15 PM

I get out quite often. I just bring my laptop with me.
Critter

Critter wrote on 03/05/07 1:16 PM

lol.

fair nuff
David

David wrote on 03/05/07 2:01 PM

do you need the "as Application" on the end, as I didn't think you would need to caste it as an Application?

...or is it just there for the good looks? :-)
Joe Rinehart

Joe Rinehart wrote on 03/05/07 2:49 PM

Application.application is of type Object....so it's not *necessary*, but I like to use strict typing whenever I can, letter the compiler save me from the inevitable "wtf?" I'd get when I made this kind of typo:

var someFlashVar:String = Application.application.paarmeters.foo

In reality, the code looked like this:

public function flashVar(name:String):String {
   var application:Application = Application.application as Application

   if (application.parameters == null || application.parameters[name] == null) {
      var e:Error = new Error("Flashvar not found!");
      e.name = "Environment.flashVar.notFound";
      throw(e);
   } else {
      return application.parameters[name];
   }
}
David

David wrote on 03/05/07 3:20 PM

...Sorry, I should have written some code before I commented!
you are right:

trace("type is" + typeof Application.application);

traces "object", so I would be casting it to!
Jaime Metcher

Jaime Metcher wrote on 03/05/07 9:42 PM

It reminds of that Microsoft classic:

Unknown error (unknown) in module unknown:unknown

or words to that effect
DannyT

DannyT wrote on 03/06/07 3:49 AM

Who'd have ever thought this would have ended up being educational to someone :P
Erwin Verdonk

Erwin Verdonk wrote on 03/07/07 2:35 AM

Now I'm wondering Joe...why create a var reference instead of just using Application.application? Are you that lazy ;-)?

Write your comment



(it will not be displayed)