In Flex 4 is it allowed to use states in Spark MXML item renderers?
I am asking this, because there are already "builtin" states like
<s:states>
<s:State name="normal"/>
<s:State name="hovered"/>
</s:states>
Can I add my own custom states, like "ingame" and "inlobby"?
Should I still write out the "normal" and "hovered" even if my AS3 code in the MXML item renderer doesn't use/need them?
In Flex 4 is it allowed to use states in Spark MXML item renderers?
Yes! A renderer is just a component like any other; and you can add states if you wish.
I'm not sure how a Flex List handles setting the state of the renderers. So, it seems possible that the states in your renderer may get changed from your "Custom" state to one of the Flex states. You may have to override the currentState variable to prevent this sort of change.
Should I still write out the "normal" and "hovered" even if my AS3 code in the MXML item renderer doesn't use/need them?
No, don't add them if you don't need them. When a mouse interaction (like hovering) occurs, ItemRenderer
will end up calling its getCurrentRendererState()
method to decide what state to set on the renderer. In that method there are many statements like this:
if (hovered && hasState("hovered"))
return "hovered";
If nothing matches, it will leave the renderer's state unchanged.