Remote Synthesis
Search my blog:
Viewing By Entry / Main
Feb 11, 2008

Stupid Flex Mistakes

In the interest of sharing I am posting a dumb mistake I made while working on a Flex/AIR project that uses Cairngorm. Hopefully my shame will help someone one day. I also want to open this up to others to share some of their most embarrassing Flex/AIR mistakes in the comments.As those of you who use Cairngorm know, you can access the instance of the ModelLocator singleton my calling the getInstance() method. This makes variables and other elements available throughout your application (rather than referring them through hard-coded references to application elements).

Well, I had a UI element that needed to be called throughout my application via a pop-up which I decided to add to the model to make it easily accessible (there might be a better means of having done that...I am open to suggestions). After attaching this UI element to the model, I could no longer compile my Flex application. Hitting run would cause adl.exe to suck up every available byte of memory on my computer essentially locking up my entire machine (for example, it sucked up 600MB within seconds of hitting run).

Eventually I figured out what was the cause of this. My UI element called getInstance() on the ModelLocator. So, in effect, I created a perpetual loop whereby when I called my model it called the UI element which called my model that called my UI element and so on... Yes, dumb! I guess that's what happens when you do off-the-cuff refactoring.

Anyway, anyone else wish to share a stupid mistake they have made in Flex/AIR? You know, for the benefit of the noobs (like me apparently). :)

Comments
Daniel Harfleet
Hi, I don't think you should be attaching elements of the view to the Model, although I can't work out from you blog entry exactly what you are trying to do, can I suggest you take a look at this blog entry, by Alex Uhlmann ( http://weblogs.macromedia.com/auhlmann/archives/2007/02/creating_a_popu.cfm#more ). Alex is one of the developers who has worked on Cairngorm and also uses Cairngorm in enterprise projects, dan


Brian Rinaldi
Thanks for the link Dan. I did figure it wasn't exactly best practice (though I should add this is a quick prototype). I had actually considered an observer, but I had figured perhaps that would be something to refactor if this application ever went from proof-of-concept to production ready. Nonetheless, I had not seen that tutorial so thanks.


Brian Rinaldi
As a follow up, I went ahead and used an observer. This is a case of doing a "shortcut" to create a proof of concept and it actually takes longer than the real solution.


Douglas Knudsen
my fav stupid mistake: after adding a new Command and new Event, I add code to fire said event in the UI. I then spend a hour figuring out why the heck my Command isn't doing its thing. ugh, I left out a wee little step, something to do about control. errr.... DK


Dusty Jewett
DK: Commands/Events kill me too... My most untrackable mistake... I remember to edit the controller, but because I copy to create new Command/Event pairs, I forget to change the super(EVENT_TYPE) call in the event constructor. The correct event fires, but the wrong command... you need a beer after those debug sessions.


Abhijeet
When I read first paragraph, I was wondering what could be the mistake. It certainly would have been head scratching one. I had done many mistakes in programming but don't have one at my fingertips. Probably, I am too sleepy. But I love mistakes, because that always teach you something new. Isn't it?


Write your comment



(it will not be displayed)