Flex 2 MXML Component Development

So I spent most of this weekend creating a few MXML and AS3 based components in preparation for my talk at Flash on the Beach in December. The thing that has struck me when developing MXML based visual components is that it is more of a process to pre-fabricated / pre-configure components. Thus saving on implementation time by not having to configure them once in situ. It reminds me of code snippets in Dreamweaver (code based but with visual elements).

For example if you are form building does it not make sense to pre-configure a selection of ComboBoxes so they have the ability to display information you would usually have in a form. Things like a salutation selector, or country drop down:

This is a quick example of how to extend a ComboBox to have pre-filled data (this way all you need to do is include it in your application and link it into your Event model). Perhaps not ideal – for a a start all of the values would be hard coded but you get the premise.

Obviously you can also extend your own custom MXML components if you needed to add additional functionality. The example below doesn’t add any additional functionality but you can see it is extended off of FGComboBox. So when implemented it too will have the same dataprovider values.

It doesn’t end there though – you can get quite complex in your fabrication if you start at a lower level – take <mx:Panel></Panel> as a base and you can start to do all manner of composition. The example below shows a quick lay-up of a form (I wouldn’t do it this way normally but it helps illustrate the point). Notice that it also includes 2 custom MXML components as part of the layout controls

What if we need to add functionality to our component? Well we can do that too. However you must remember not to put your <mx:Script></Script> tag or any other come to that, outside of your base component tag otherwise it will error along these lines: “The prefix “mx” for element “mx:Script” is not bound”.

The sample below shows a quick and dirty handler to respond to a click of the Reset button. Nothing special and not how you would implement it in a proper application but you get the gist of what you can do.

Flash on the BeachHopefully that has given a quick (yet dirty) guide to getting MXML based components going. And remember if you want to know more you can catch my talk on Flex 2 and AS3 component development at Flash on the Beach in 5 weeks time

NOTE: It appears the syntax hiliter I use is screwing the code up so I have uploaded the files as a project here


5 comments for “Flex 2 MXML Component Development”

  1. Nice smiley inside the code!!!!!!!!!

    Posted by Gustavo | October 30, 2006, 15:49
  2. Yes, I’m going to sort that out in the CSS tonight once I get home…You can switch it to ‘Plain Text’ view and it will get rid of it. :P

    Posted by FlashGen | October 30, 2006, 16:38
  3. […] Register « Flex 2 MXML Component Development Flex 2 Component example files uploaded […]

    Posted by FlashGen.Com .: blog :. » Flex 2 Component example files uploaded | November 2, 2006, 15:01
  4. css? :p the plain text version is missing the chars that were translated into a smiley

    Posted by mofo | November 2, 2006, 14:58
  5. I’ve uploaded the actual files – you can get them in downloads (via the link at the bottom of this post.

    Posted by FlashGen | November 2, 2006, 15:00

Post a comment