動的状態を探している場合-これが解決策です(最初の2つの状態-default
とbig
-はコンパイル時に追加されます。3番目の状態Bang-a-Gong
は実行時に追加されます):
private function init():void {
// Create a new state and give it a name.
var stateBang:State = new State();
stateBang.name = 'Bang-a-Gong';
// Set the overrides with an array of AddChild, AddItems,
// RemoveChild, SetEventHandler, SetProperty, and SetStyle
stateBang.overrides =
[ new SetProperty( btn, "label", "Bang-a-Gong" ),
new SetProperty( btn, "height", "150" ),
new SetProperty( btn, "width", "300" ),
new SetStyle( btn, "fontSize", "22" ),
new SetStyle( btn, "fontWeight", "bold" ),
new SetStyle( btn, "color", "#FF0000" ) ];
// Add our new state to the available states of this component.
this.states.push( stateBang );
// Just for kicks lets add a transition for this state.
var transition:Transition = new Transition();
transition.toState = 'Bang-a-Gong';
// Create a new transition effect.
var resize:Resize = new Resize( btn );
// Create an composite effect, either: Sequence or Parallel.
var sequence:Sequence = new Sequence();
// Add our resize effect.
sequence.addChild( resize );
// now add our composition effect to the transition we created.
transition.effect = sequence;
// Push our new transition into the transitions array for this component.
this.transitions.push( transition );
}
別のケースでは、私が正しく理解していれば、メインアプリケーションでオブジェクトを作成し、すべての子コンポーネントから。を介してそれにアクセスする必要がありますFlexGlobals.topLevelApplication
。
子の状態を変更する場合は、状態がすでに定義されているインスタンスを1か所に配置し、後でそれらを子コンポーネントにコピーする必要がありますが、それらがすべてカスタムロジックである場合はどうでしょうか。
それで、それが助けになるなら、私に知らせてください。