Flex ArrayCollection - accesing object methods / attributes?
Maybe i didn't get the real meaning of the ArrayCollection, but first of all some code
public var test1:AkwRep = new AkwRep(1,200,200,2,86,2010,2012,334342,"Typ","Standort","Testname","url","owner",true);
// Objekte in ein Array
public var akwArray:Array = new Array(15);
public function addAkw():void {
akwArray[0] = test1;
}
public var akwList:ArrayCollection = new ArrayCollection(akwArray);
(akw means Atomkraftwerk -> nuclear power plant ;) )
so i've got an array with akwRep-Objects. For databinding i put it into a ArrayCollection. No problems so far. But now i want to do something like
<s:Label text={akwList.getItemAt(0).getAkwName()} />
while getAkwName is a method in AkwRep.as which returns a string. but this didn't work - I can not acces any methods or attributes via ArrayCollection.
Is there a solution? If i try it with the array, flexbuilder says he can't do databinding with akwArray[0] ...
Edit: some new code
This is in the <fx:script>
tag in my main app
[Bindable]
// AKW-Objekte erstellen
public var test1:AkwRep = new AkwRep(1,200,200,2,86,2010,2012,开发者_JS百科334342,"Typ","Standort","Testname","url","owner",true);
[Bindable]
// Objekte in ein Array
public var akwArray:Array = new Array(15);
public function addAkw():void {
akwArray[0] = test1;
}
[Bindable]
public var akwList:ArrayCollection = new ArrayCollection(akwArray);
public function init():void{
trace(akwList.getItemAt(0));
}
and this is my AkwRep.as
public class AkwRep
{
// Attribute
// some more attributes right here
public var typ:String;
public var standort:String;
private var akwName:String;
[Bindable]
public function get AkwName():String {
return this.akwName;
}
// Konstruktoren
public function AkwRep(id:Number, x:Number, y:Number, alter:Number, amNetz:Number, offOhneVerl:Number, offMitVerl:Number, leistung:Number, typ:String, standort:String, akwName:String, wikiurl:String, owner:String, moratorium:Boolean) [...]
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
creationComplete="init()" xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var akwList:ArrayCollection = new ArrayCollection();
public var test1:AkwRep = new AkwRep(1,"Testname");
public function addAkw():void {
akwList.addItem(test1);
}
]]>
</fx:Script>
<mx:VBox>
<s:Label text="{AkwRep(akwList.getItemAt(0)).akwName}" />
<s:Button click="addAkw();" label="Add" />
</mx:VBox>
</s:Application>
In MXML
package {
[Bindable]
public class AkwRep {
private var _akwName:String;
public function get akwName():String {
return "Name: " + _akwName;
}
public function AkwRep(id:Number, akwName:String) {
_akwName = akwName;
}
}
}
In AkwRep.as
精彩评论