This was one of the MUST SEE presentations on my list. Building reusable components is a great way to provide customized Flex functionality and I was very excited to actually get a seat in this packed session. There were at least 40 people sitting on the floor!. I took a lot of notes and will make some available below. The slides are a great reference and they are available at: Chafic Kazoun's blog located at http://www.rewindlife.com
Flex Components are reusable components that are self contained. Using component are a proper way to write maintainable applications in Flex. Using components can be a lifesaver for team environments because it helps insulate the impacts of change in component development.
A cheat sheet for starting a new custom component:
- Decide on what the component should do
- Don't overthink the API just yet
- Provide protected data access and limit what can be passed into the component
- Finally, decide on the public API
Setting up the component:
- The root MXML tag is the base class. This is often a container you use to contain the component.
- Next, specific a package through a directory structure.
- You MUST reference the Flex mxml namespace.
- Using the component in a Flex application means you must import the component and assign it to a namespace.
- Treat the component like a black box.
- When you import a component into a Flex application, Flex Builder will find the namespace and give code hints based on the properties of the component.
- If you make a public bindable, the get and the set are both made binable regardless if the [bindable] directive is on the get or the set declaration.
- Using past tense events is not good practice. For example, FormChangedEvent is not a good representation, use FormChangeEvent instead.
- Override the public function clone inside your Event class. The clone should return a new event and provide the setup code for initializing the event.