昨日phtrivierさんが私にhow to send an array to a new/sub-windowと表示されました。ArrayCollectionを新しい/サブウィンドウに送る方法は?
ここでは、この静的なデータソースを、ArrayCollectionに読み込むXMLファイルに置き換えました。残念ながら、ArrayCollectionは、新しい/サブウィンドウにその一部を送信しようとすると、Arrayとは異なる動作をすることが判明しました。
ArrayCollectionでどうすればいいですか?
または、Arrayを送信して簡単な道を踏んで、代わりにXMLをArrayCollectionではなくArrayにロードする方法を探しますか?私はが ACが提供する追加機能を必要とするとは思わない。
MyMain.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication ...stuff... creationComplete="settingService.send()">
<fx:Declarations>
<s:HTTPService id="settingService" url="data.xml" result="settingService_resultHandler(event)"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
// import dependencies
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
// variables
[Bindable] private var xmlData:ArrayCollection;
// collect static data
private var staticData1:Array = new Array('The Eiffel Tower','Paris','John Doe');
private var staticData2:Array = new Array('The Strip','Las Vegas','Jane Doe');
private var staticData:Array = new Array(staticData1, staticData2);
// collect xml data
protected function settingService_resultHandler(event:ResultEvent):void
{
xmlData = event.result.settings.photo;
}
// open window & send data in Array, WORKING
public function openWin1(inData:Array):void
{
var w:MyWindow1 = new MyWindow1();
w.inData = inData;
w.open();
}
// open window & send data in ArrayCollection, NOT WORKING
public function openWin2(inData:ArrayCollection):void
{
var w:MyWindow2 = new MyWindow2();
w.inData = inData;
w.open();
}
]]>
</fx:Script>
<!--opening windows, adding an array, WORKING-->
<s:Button x="10" y="10" width="240" label="open a sub-window 1" click="openWin1(staticData[0]);"/>
<s:Button x="10" y="30" width="240" label="open a sub-window 2" click="openWin1(staticData[1]);"/>
<!--opening windows, adding an arraycollection, NOT WORKING-->
<s:Button x="10" y="60" width="240" label="open a sub-window 1" click="openWin2(xmlData.getItemAt(5));"/>
<s:Button x="10" y="80" width="240" label="open a sub-window 2" click="openWin2(xmlData[5].source);"/>
<s:Button x="10" y="100" width="240" label="open a sub-window 3" click="openWin2(xmlData.getItemAt(5).source);"/>
</s:WindowedApplication>
MyWindow1.mxml(、すべての後にその作業罰金する必要があります)私自身の解決策が見つかり
<?xml version="1.0" encoding="utf-8"?>
<mx:Window ...stuff...>
<mx:Script>
<![CDATA[
// variables
[Bindable] private var windowData:Array;
// receive data
public function set inData(outData:Array):void {
this.windowData = outData;
}
]]>
</mx:Script>
<mx:TextInput id="comment" x="10" y="10" text="{windowData[0]}"/>
<mx:TextInput id="location" x="10" y="30" text="{windowData[1]}"/>
<mx:TextInput id="author" x="10" y="50" text="{windowData[2]}"/>
</mx:Window>
MyWindow2.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Window ...stuff...>
<mx:Script>
<![CDATA[
// import dependencies
import mx.collections.ArrayCollection;
// variables
[Bindable] private var windowData:ArrayCollection;
// receive data
public function set inData(outData:ArrayCollection):void {
this.windowData = outData;
}
]]>
</mx:Script>
<mx:TextInput id="comment" x="10" y="10" text="{windowData.comment}"/>
<mx:TextInput id="location" x="10" y="30" text="{windowData.location}"/>
<mx:TextInput id="author" x="10" y="50" text="{windowData.author}"/>
</mx:Window>
デバッグを試したことはありますか?インデックス5のxmlData内のオブジェクトは何ですか?それはArrayCollectionですか?ランタイムエラーが表示されませんか? –
最初のボタン(openWin2(xmlData.getItemAt(5)))は機能しますが、[object Object]はテキストフィールドに表示されます。 その行は、Flash Builderでもこのエラーを示しています。1118:静的型Objectの値を、関連性のない型mx.collections:ArrayCollectionに暗黙的に強制変換します。 2番目のアプリケーションでクラッシュする:TypeError:エラー#1034:強制型変換が失敗しました:mx.utils :: ObjectProxy @ 6260781をMyMainのmx.collections.ArrayCollectionに変換できません... 3番目の理由は、Flash Builderもう私の更新を認識していないようです。私はすでにそれを再インストールした、それは怒っている。 – Brugman
私はデバッグパースペクティブを調べてみましたが、どこにでも自分のデータを見つけることができません。 xmlDataは多次元のArrayCollectionです。私が間違ったボタンを押すまでは、実行中にエラーが出ることはありません。 – Brugman