Fundamental bug in Flex Builder 1.5?

Flex Builder 1.5 appears to have such a fundamental bug in it that I was actually afraid to post something about it earlier, without double-and-triple checking my results and extensively testing it out, for fear of having overlooked something very minor. Basically, Flex Builder loses the ability to preview your applications in Design View if you subclass mx.core.Application or mx.containers.Form. Although this is perfectly legal -- and actually, I would argue, a best practice (more on that later) -- and although the resulting applications run when compiled, Flex Builder's Design, Run and Debug features stop working.

I am still hoping that there is at least an undocumented way to tell Flex Builder, "Hey, I'm extending Application/Form, so you can go ahead and display it as if it was an Application/Form" but I haven't been able to find such a way as of yet (and I've looked extensively into to the extensibility layer for Dreamweaver too without any luck in locating hooks into the Flex Design View renderer.)

Thus, the following simple example renders correctly in Flex Builder:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="" childrenCreated="onChildrenCreated()">
  3. <mx:Script>
  4. <![CDATA[
  5. var counter:Number = 0;
  7. function click ()
  8. {
  9. counter++;
  10. aTextInput.text = "You've clicked "+counter+" time";
  11. aTextInput.text += ( counter == 1 ) ? "": "s";
  12. aTextInput.text += "! Good on you!";
  13. }
  14. function onChildrenCreated ()
  15. {
  16. aButton.addEventListener ( "click", this );
  17. }
  18. ]]>
  19. </mx:Script>
  20. <mx:TextInput id="aTextInput" />
  21. <mx:Button id="aButton" label="Button"/>
  22. </mx:Application>

While the following does not:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <flexBuilderBug:ApplicationSubclass
  3. xmlns:flexBuilderBug="com.ariaware.flexbuilderbug.*"
  4. xmlns:mx=""
  5. >
  6. <mx:TextInput id="aTextInput" />
  7. <mx:Button id="aButton" label="Button"/>
  8. </flexBuilderBug:ApplicationSubclass>

The code for the ApplicationSubclass, which you need to place in the WEB-INF\flex\user_classes\com\ariaware\flexbuilderbug folder of your Flex application, is given below:

  1. class com.ariaware.flexbuilderbug.ApplicationSubclass extends mx.core.Application
  2. {
  3. // Components
  4. var aButton:mx.controls.Button;
  5. var aTextInput:mx.controls.TextInput;
  6. // Properties
  7. var counter:Number = 0;
  8. function init ():Void
  9. {
  10. super.init();
  11. addEventListener ( "childrenCreated", this );
  12. }
  13. //
  14. // Event Handlers
  15. //
  16. function childrenCreated ()
  17. {
  18. aButton.addEventListener ( "click", this );
  19. }
  20. function click ()
  21. {
  22. counter++;
  23. aTextInput.text = "You've clicked "+counter+" time";
  24. aTextInput.text += ( counter == 1 ) ? "": "s";
  25. aTextInput.text += "! Good on you!";
  26. }
  27. }

Similarly, if you were to include a Form subclass instead, Flex Builder cannot render a preview of that either.

If, indeed, there isn't a way to get the current build to display subclasses of Application/Form correctly, this is a major, fundamental bug and needs to be fixed as the first order of business. Subclassing the Application and Form classes is how Flex applications should be built. By following this methodology, you remove all code from the MXML files, making your applications easier to maintain and scale. (The currently de facto practice of including <script> tags and mixing code into your MXML are stages that we went through in the Flash world and grew out of.) ARP also supports this latter method of working and, in a series of articles that will be released this month (along with an update to ARP itself), you will see how this way of working also makes it child's play to migrate applications from Flash to Flex.

I do hope that there is a way to workaround this issue in Flex Builder currently and, if not, that it will be fixed in the next update.