MVCアーキテクチャ....だけでなく、簡単な例では、単にモデルの一部:
package
{
[Bindable]
public final class ShellModelSingleton
{
public var selectedStatus:ArrayCollection;
////////////////////////////////////////////
// CONSTRUCTOR
// ****DO NOT MODIFY BELOW THIS LINE*******
///////////////////////////////////////////
public function ShellModelSingleton(){}
/****************************************************************
* Singleton logic - this makes sure only 1 instance is created
* Note: you are able to hack this since the constructor doesn't limit
* a single instance
* so make sure the getInstance function is used instead of new
* ShellModelSingleton()
*****************************************************************/
public static function getInstance():ShellModelSingleton {
if(_instance == null) {
_instance = new ShellModelSingleton();
}
return _instance;
}
protected static var _instance:ShellModelSingleton;
}
}
次に、あなたがこのような任意のコンポーネントからシングルトンを更新して使用することができます。
[Bindable] private var model:ShellModelSingleton =
ShellModelSingleton.getInstance();
コンポーネント1
<mx:DataGrid id="myDG" dataProvider="{model.selectedStatus}" />
コンポーネント2
<mx:List id="myList" dataProvider="{model.selectedStatus}"
labelField="label" />
selectedStatusコレクションの変更は、両方のコンポーネントで更新されます。
共通の親コンポーネントをすべて共有していないとしますか? –
私はあなたのアプリケーションコンポーネントのように親コンポーネントを意味しました。基本的にそこで宣言された変数には、グローバルスコープがあります。 – CookieOfFortune