5 Replies Latest reply on Jan 12, 2007 2:08 AM by Bjørn Børresen

    Creating Flex applications without MXML but with AS3

    Bjørn Børresen Level 1
      To me it seems logical that if I want to build an application I should use AS3 to create reusable components, classes, the layout, etc.

      .. however, searching around on the web I exclusively find Flex tutorials and examples using MXML. This is also true for the books (e.g. Adobe Flex 2 - Training from the source") -- why is this?

      Is it wrong of me to think it'd be best to create everything in AS3? Do anyone have links to tutorials etc. where they use AS3 to build Flex applications?
        • 1. Re: Creating Flex applications without MXML but with AS3
          YuliyaR
          Although I have not seen tutorials about this I did create a test app using the following approach:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml"
          xmlns:lib="components"
          width="100%"
          height="100%"
          creationComplete="initGrid()"
          scroll="false"
          >

          <mx:Script>
          <![CDATA[
          ..... AS 3 code here to create/populate app - datagrid in my case
          ]]>
          </mx:Script>

          <mx:VBox id="_box" width="100%">
          <mx:Button id="hideShowCols" label="Hide Empty Columns" click="doColumnAction();"/>

          <mx:DataGrid id="delinquenciesGrid"
          alternatingItemColors="[#cce6ff, #e8ffff]"
          alpha="0.5"
          lockedColumnCount="3"
          allowMultipleSelection="true"
          rowCount="20"
          headerColors="[#cccccc]"
          fontFamily="Arial"
          visible="false"
          preinitialize="detectClick();"
          >

          </mx:DataGrid>

          </mx:VBox>

          </mx:Canvas>


          Even the data grid does not need to be "declared" in MXML, it was just a faster way to do it for me - you could do
          canvas_id.addChild(...) any element/item that you create in AS3.... or in my case i was doing _box.addChild(newGrid)

          • 2. Re: Creating Flex applications without MXML but with AS3
            Bjørn Børresen Level 1
            What you did was MXML with some AS3 code sprinkled in between ;-)

            I mean having an application where the only MXML code is this:

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical" xmlns:app="app.*">
            <app:Test />
            </mx:Application>

            It inits the Test class which builds the GUI etc.
            • 3. Re: Creating Flex applications without MXML but with AS3
              FlightGuy Level 1
              I don't think there's anything wrong with using AS for your components - I do so for most of my components if they're not containers with layout inside them.

              Using FlexBuilder gives you graphical layout capability, and that's a good and useful thing to use to layout components. If I'm extending a control and changing its behavior I always use AS because it's a bit clumsy to do that in MXML, and there's no benefit for it. Sometimes, however, I'm creating a component to use, for example, as a popup - in this case I create an mxml file that extends TitleWindow and I can use the visual editor to layout the contents.

              In any application you have to end up with something visual that involves layout, so there's seldom likely to be an argument to not use MXML at least for the Application. There's no runtime performance gain from using AS - though I guess the compiler saves a little bit of time.

              So in your example, I agree there's nothing wrong with it if the app:Test class is entirely dynamic, but if you're doing static layout inside the Test class you're just making it cryptic for yourself and any developer maintaining that code in the future.

              Tim
              • 4. Re: Creating Flex applications without MXML but with AS3
                FlightGuy Level 1
                To add to that - even if you're not using FlexBuilder, describing a container with its contents in MXML still shows the hierarchical relationship of different components, which in AS is completely abstract, so even there I'd argue for using MXML over AS for components that involve layout.

                Tim
                • 5. Re: Creating Flex applications without MXML but with AS3
                  Bjørn Børresen Level 1
                  I'm convinced - MXML it is :)

                  Thanks for your insight.