index.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" horizontalScrollPolicy="auto" verticalScrollPolicy="auto" xmlns:s="library://ns.adobe.com/flex/spark"
initialize="{newfile.send()}" xmlns:local="*">
<mx:Style source="CSS/goodlist.css"/>
<mx:Script>
<![CDATA[
import com.adobe.serialization.json.*;
import mx.collections.ArrayCollection;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.utils.URLUtil;
public var jsonStr:String;
public var jsonArr:Array;
[Bindable]
private var catalog:ArrayCollection;
protected function newfile_resultHandler(event:ResultEvent):void
{
jsonStr = String(newfile.lastResult);
jsonArr = JSON.decode(jsonStr) as Array;
var products:ArrayCollection = new ArrayCollection(jsonArr);
var temp:ArrayCollection = new ArrayCollection();
var product:Product;
for each(var pro:Object in products)
{
product = new Product();
product.name = pro.name;
product.ID = pro.ID;
product.category = pro.category;
product.description = pro.description;
product.price = pro.price;
product.unitID =pro.unitID;
product.cutoff = pro.cutoff;
product.store = pro.store;
product.locationID = pro.locationID;
temp.addItem(product);
}
catalog = temp;
show.text = String(catalog.length);
saleStack._catalog = catalog
}
]]>
</mx:Script>
<mx:HTTPService url="http://localhost/newfile.php" id="newfile"
result="newfile_resultHandler(event)"
method="GET" resultFormat="text">
</mx:HTTPService>
<mx:VBox>
<local:saleView width="100" height="100" id="saleStack" showEffect="WipeDown" hideEffect="WipeUp"/>
<mx:Label id="show"/>
</mx:VBox>
</mx:Application>
saleView.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300"
initialize="{this.canvas1_initializeHandler()}">
<fx:Declarations>
</fx:Declarations>
<fx:Script>
<![CDATA[
import CatalogEvent;
import Product;
import flash.utils.Dictionary;
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
private var productCatalog:Array;
[Bindable]
public var _catalog:ArrayCollection;
protected function canvas1_initializeHandler():void
{
test.text = String(_catalog);
}
]]>
</fx:Script>
<mx:Label id="test"/>
</mx:Canvas>
затем test.text показывает, что "null"
но если удалить test.text = String(_catalog);
и измените тест метки следующим образом
<mx:Label id="test" text="{_catalog}"/>
тест покажет _catalog
Я не знаю, я хочу использовать _catalog во многих других функциях
Пожалуйста .....