To clarify, you want your "left" Label to appear in both "state1" and "state2", and you want your "right" Label to only appear in "state2"?
If that is the case, try removing the "includeIn" from your "left" Label. That way when the "right" Label is added in "state2", it will be positioned after the "left" Label, giving you the layout that you desired.
I gave a simplified example, but I have more than 2 states. In this example I can have an other state3 where I don't want "left" nor "right" Labels. In this case I think I need the includeIn in my "left" Label.
Also, I tried to create my 2 states without the basedOn :
and set my component1 includeIn = "state1", and my component2 includeIn = "state1, state2"
For labels it's ok, but in my case, left component1 is a Datagrid. So if I do this, the datagrid is redrawn and I lost selection, scroll, etc. When I declare state2 as "basedOn" state1, my Datagrid is not redrawn, I prefer this, but then it is displayed on the right, as I described...
So what is the solution ? Is this a bug in flex states ? Or do I use them the wrong way ?
Have you tried using stateGroups? If that doesnt work Im not sure if you can
accomplish what you are trying to do with MXML alone. If your are comfortable
enough doing some coding, you might try extending your component class and
declaring your states through actionscript. When you create your states in this
fashion you can manually assign overrides to the them, and you should be able to
use the AddItems class to control where your components are added and the order
that they are added in. Look into the itemsFactory property of the AddItems
class. If you use a DeferredInstanceFromFunction class to create the instance of
your DataGrid, it should always return the same instance of the DataGrid, so I
would think that your selection and scroll would be unchanged.
I tried :
<s:State id="state1" stateGroups="group1"/>
<s:State id="state2" stateGroups="group1"/>
<s:DataGrid includeIn="group1" ....../>
<s:Label includeIn="state2" ............./>
I want state1 to display my Datagrid on the left
I want state2 to keep Datagrid on the left with its selectedItem, scroll, etc. AND display the Label on the right
But if I use stateGroups, the layout is respected but my datagird is redrawn, I loose selectedItem and scroll.
Is it really impossible using mxml states ?