好吧,我有一个问题,在ItemProperty类中搜索数组的更改。当我调用跟踪项数组长度时,它比得到0.但是在ItemProperty类中只有RecieveIndex函数项长度超过2.甚至ReturnData()得到0.问题是如何得到这个数组的最终结果(Item)在InventoryData类中? 那是班级,当我得到0:
public class InventoryData extends Sprite {
private var item:ItemProperty = new ItemProperty();
public function InventoryData(){
trace(item.Item);
trace(item.Item.length);
//trace(item.ReturnData());
}
}
形成数组的类。在RecieveIndex方法中项目长度大于0。
public class ItemProperty extends Sprite{
public var Item:Array = [];
public function ItemProperty() {
var connect:Connection = new Connection();
connect.setRequest("Select", "`inventory`", ["all"], ["all"], InventoryContent);
}
private function InventoryContent(RecieveData:Array):void
{
var picking:Connection = new Connection();
picking.setRequest("Select","`weapon`",["all"],["id IN("+RecieveData[0].contents.toString() + ")"], InventotyData);
}
private function InventotyData(RecieveData:Array):void{
var indexdecode:Connection = new Connection();
for(var i:uint=0; i<RecieveData.length; i++)
{
indexdecode.loadImageFromBase64(RecieveData[i].id, RecieveIndex);
}
}
public function RecieveIndex(index:int):void {Item.push(index); }
public function ReturnData():Array {return Item;}
}
答案 0 :(得分:0)
我在评论中提到的事件就是这样:
public class InventoryData extends Sprite {
private var item:ItemProperty = new ItemProperty();
public function InventoryData(){
item.addEventListener(ItemProperty.ARRAY_READY, onArrayReady);
}
private function onArrayReady(e:Event):void {
trace(item.Item.length);
}
}
在ItemProperty类中,您声明一个新常量:
public static const ARRAY_READY:String = "arrayReady";
一旦你的数组中填充了你想要检索的项目,你就添加:
dispatchEvent(new Event(ARRAY_READY));