0 Replies Latest reply on Aug 12, 2006 5:32 PM by gmcbay

    Flex 2 SDK / mxml

    gmcbay
      I've been programming a fairly complex Flash app for a while now. It began as a Flash 8 app. I am more of a programmer than a designer, so my program was pretty much implemented in *.as files even in Flash 8. I've been porting the application to Flex 2 SDK/Flash 9/ActionScript 3 (which suits my workflow fantastically since I tend to do everything in code) and I'm 99% done and really happy with the results... The only issue I'm running into is this one:

      When porting my app to Flex 2 SDK, I opted to just make a class called Player which subclasses flash.display.Sprite and then I would pass Player.as into the mxmlc compiler directly, avoiding the use of any MXML at all. Player acts as my top level displayobjectcontainer under the Stage. This works great, except the last class I need to port over for my current application uses an mx.control.TextArea. I tried to just "new" one and then addChild it to the parent, and while that doesn't cause any compilation errors or runtime exceptions or anything, the TextArea never displays. I did some research and it seems like the only reasonable way to add a TextArea is to define it in MXML, which means that I now need an MXML for my project. There are loads of example MXMLs to be found all over the place, but all the ones I find tend to be way more complicated that I want or need. My basic question is, what is the easiest way to take what I have and get it working with an MXML shell with the least amount of changes to my app, which works great as-is (other than the fact that I can't use mx controls without an MXML).

      I tried the obvious solution, making a simple MXML that references my Player class (which I changed to subclass UIComponent) and a TextArea:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application width="400" height="400" xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*">
      <Player id="player"/>
      <mx:TextArea id="titleArea" width="10" height="10" text=""/>
      </mx:Application>

      This kind of works the way I would expect, except the 'stage' member of Player is null -- why is this? How can I get a reference to the global stage if my top level UIComponent class' 'stage' member is null? Why is it null? It isn't null when I mxmlc the Player.as file directly. Since I do a lot of my button/other control resizing based on stage height and since I want to grab the stage's loaderInfo.parameters, I really need a reference to the stage!

      It may be kind of hard to follow what I'm asking because in a way I'm trying to subvert the 'Flex' way of doing things and have as little MXML as possible, but if anyone has any pointers on how I can do this, I'd love to hear them. Please keep in mind I'm using the Flex 2 SDK, not Flex Builder, so I'd prefer to hear how I can make this work just with MXML and ActionScript, not via the Flex Builder UI.