Question

Well, I have a problem, with searching changes of array in ItemProperty class. When i calling to trace item array length, than it gets 0. But in ItemProperty class only in RecieveIndex function item length getting more than 2. Even ReturnData() got 0. The question is how to get final result of this array(Item) in InventoryData class? That is class, when i got 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());
    }
}

Class where array was formed. In RecieveIndex method Item length more than 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;}
}
Was it helpful?

Solution

Something like this with the event I mentioned in my comment:

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);
    }
}

In ItemProperty class you declare a new constant:

public static const ARRAY_READY:String = "arrayReady";

and once you have the array filled with the items you want to retrieve, you add:

dispatchEvent(new Event(ARRAY_READY));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top