ユーザーがモバイルFlexアプリケーションで選択したアイテムの値を取得する際に問題が発生しました。リストからアイテムを選択すると、そのアイテムをArrayCollectionに配置します。しかし、値(trace())を確認すると、値は[object Object]であり、オブジェクトの実際の値にアクセスできないようです。これが私がしていることです:
private var selectedPlayers:ArrayCollection = new ArrayCollection();
private var numOfPlayers:int;
...
//check if item is not already in selected players list
if(!selectedPlayers.contains(playerList.selectedItem))
{
//add the selected item to the selected players list
selectedPlayers.addItem(playerList.selectedItem);
numOfPlayers++;
trace("selected Players: " + selectedPlayers);
}
trace()からの出力:
選択したプレイヤー:[オブジェクトオブジェクト]
アドバイスや洞察をありがとうございました。
更新:動作するコードは次のとおりです。
[Bindable]
public static var selectedPlayers:ArrayCollection = new ArrayCollection([
{Name: "testname" }]);
...
//check if item is not already in selected players list
if(!selectedPlayers.contains(playerList.selectedItem.PName))
{
//add the selected item to the selected players list
selectedPlayers.addItem({Name: playerList.selectedItem.PName});
numOfPlayers++;
}