States in components inheriting from a custom class

A standard recommendation is to separate view from controlling code. A good way to achieve this in Flex is to have a mxml class that contains nothing but view and to move all the controlling code to a superclass.

LoginScreen.mxml


<p:LoginScreenClass xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:p="path.to.LoginScreenClass.*" />

LoginScreenClass.as


package path.to.LoginScreenClass
{
import mx.containers.VBox;
public class LoginPanelClass extends VBox {}
}

It works smoothly once you remember that in 'LoginScreenClass.as', unctions called from the mxml file needs to be declared as protected and ui elems of the mxml file that the as class refers to need to be declared as public.

Expect for one thing, states.

if you add <mx:states> in a component that inherits from a custom class that itself inherits from a Flex container, the compiler tells you that states is not allowed in that context.

A solution is given on Justin Moses' blog. "Use the same xml namespace as your base component to load up the property, even though it is inherited."

Rather than


<mx:states />

use

<p:states />

Powered by Drupal, an open source content management system