Reputation:
I expect this is easy but a lot of Google searching and inspecting objects on break points has not turned up the answer.
I can define states in MXML:
<s:states>
<s:State name="state_1" />
<s:State name="state_2" />
</s:states>
Then I can do this:
<s:Label id="lblTest" text="Hello" x.state_1="20" x.state_2="100" />
In Actionscript I can set property values:
lblTest.x = 150;
Question: How would I set both x.state_1 and x.state_2 for lblTest from Actionscript regardless of the current state?
Upvotes: 0
Views: 273
Reputation: 7110
There's nothing that's quite as simple when working in Actionscript. When you compile your mxml file with state-specific properties, Actionscript code like this gets generated in its constructor:
states = [
new State ({
name: "state_1",
overrides: [
new mx.states.SetProperty().initializeFromObject({
target: "lblTest",
name: "x",
value: 20
})
]
})
,
new State ({
name: "state_2",
overrides: [
new mx.states.SetProperty().initializeFromObject({
target: "lblTest",
name: "x",
value: 100
})
]
})
];
If you're creating your states in Actionscript, you could do something similar. If you want to modify the state-specific properties that were already set, it's not quite as easy. You'd have to find the SetProperty
object in each state's overrides
array and replace/modify it.
Really, the power of state-specific properties is being able to define them nicely in MXML. Don't forget that you can use bindings to set the values of the properties to basically get what you want for free:
<s:Label id="lblTest" text="Hello" x.state_1="{state_1_value}" x.state_2="100" />
Upvotes: 3