explorers' club

explorations in dev, science, sci-fi, games, and other fun stuff!

mx:Component … use it!

2 Comments

My love for Flex grows more and more each day. I just found a super useful mxml tag that will save me (and you) a lot of work down the road.

Have you ever wished that you could quickly create a component without having to structure a proper class file? Not needing to plugin associated events, methods and any other internal mechanisms to get it to function with other classes or views?

If you can answer ‘yes’ to that question, then you might wanna take a look at the mx:Component tag. It is a special mxml tag that allows you to set up a component (so far just itemRenderers and itemEditors) inline without all the associated overhead with creating a new class. Much like a helper class inside an actionScript file, you can define a component within another component. You can read more here.

One thing to note: The scope of this between the <mx:Component> tags will refer to the component itself and not the actual class it resides in. Another thing is that you can define an additional <mx:script> tag inside the component. Of course one might debate then you might as well make it a real class.

Obviously you would move this inline-component over to an actual class if it became needed else where, but for rapid development in adding simple controls as itemRenderers/itemEditors this is a sure-fire way to go. I am not sure how long this puppy has been around (and I am sure someone will comment ‘I have been using this since Flex 1.5’) but I just found it and I love it!

Advertisements

2 thoughts on “mx:Component … use it!

  1. I have been using this since Flex 1.5

  2. To access the class the component resides in use the “outerDocument” scope instead of “this”.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s