Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the best practice to develop a visual component in Flex Hero?

I do it like this: I consider a component has 2 "parts", the declarative part (the visual sub-components) which I define in the skin (just mxml) and the code part (event handlers...) which I define in an action script class. I load the skin in the ctor of the action script class. I also define skin parts, states, and I bind event handlers in the partAdded function.

I am having an argument about this; that I should define the component purely in an .mxml, with listeners in the script tag, and maybe attach a skin (but the skin should be loose - maybe for reuse :-?)

I come from .NET and maybe I am biased with the code behind pattern, and I am wondering from your experience and Adobe's intent, what is the best practice to usually implement a visual component?

share|improve this question
up vote 1 down vote accepted

There are 3 ways to implement components.

1 pure ActionScript

Extend UIComponent.


MXML is just an abstraction of ActionScript. When compiling a Flex application, the source code will translate MXML to ActionScript. So, there is basically nothing wrong to have ActionScript in the fx:Script tag. There are some people who say, that a view should contain no logic (when implemented in MXML) but that is plain stupid, since you need ActionScript to define behavior.

3 SkinnableComponent (separation of behavior and visual appearance)

You extend SkinnableComponent and define a skin class. This is extremely helpful, when theming for different clients or load different visual appearances depending on a user's role.

The code behind aprouch can be achieved easily in ActionScript, wether be aggregation or inheritance. Also an MVVM can be implemented easily. But generally, that's not the pattern you use. Usually in Flex, you use MVC/MVCS.

You may want to take a look: Flash builder 4.6 - code behind approach

share|improve this answer
What i forgot: The best practice is what fits your needs. But what matters is, separater the view from the application's business logic. The views behavior can be separated if desired, but generally SkinnableComponents are easier to deal with, because of the clean separation. If no visual appearance is needed, plain ActionScript will do of course as well. – Florian Salihovic Jun 6 '12 at 15:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.