PDA

View Full Version : How to add a custom class in mxml?


baritone87
09-20-2007, 07:21 AM
I want to have a bunch of instances of an Object Class I wrote appear in a Tile. So in my mxml I have a state that has

<mx:State name="stateA">
<mx:AddChild>
<mx:Tile>
<this is where I want to add Objects that would be instances of an Object I have in a .as file>
</mx:Tile>
</mx:AddChild>
</mx:State>

How do I add my objects? I thought maybe I need to create a namespace in the main application tag. I was going to call my namespace "qs". Then I would just add:
<qs:MyCustomObject />
in between the Tile tags. Am I way off base? Are there a lot of hoops I have to jump through to get my Object in there? I believe my custom object must extend a UIInterface object to be able to add mxml drag and drop functionality so I was planning on having it extend Canvas.

Thanks in advance for any help.
B

dr_zeus
09-20-2007, 05:03 PM
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:qs="com.whatever.*"
layout="vertical">

<qs:MyCustomObject/>

</mx:Application>

You must subclass UIComponent or another Flex component type. You mentioned Canvas, and that would work fine.

baritone87
09-20-2007, 09:58 PM
Awesome! Thanks a million Josh. Got it working.
I didn't know if I was going down the right path or not. It turns out that the reason I hadn't gotten it working was that I didn't understand that making the namespace like so:

xmlns:qs="com.mydomain.*"

forces me to put the files in a different folder so flexBuilder finds them. In the end I just made my name space like this:

xmlns:qs="*"

so I can leave my .as Class files in the same directory. Since I am the only guy who will ever see this before it becomes a SWF, I assume that the namespace equalling "*" doesn't really affect anything.

Aside: Hey, I looked at your blog. I'll look for your presentation at MAX. Have fun. And thanks again for your post.

Brian

dr_zeus
09-21-2007, 05:01 PM
You don't necessarily need to put your classes in a package if they're specifically meant to be used for the project at hand. I often leave custom components that I know I'll never use again in the default * package.