Product. As File
Import usstore. model. productinfo;
Class usstore. businessobj. Product
{
Public VaR Addeventlistener: function;
Public VaR Removeeventlistener: function;
Private VaR Dispatchevent: function;
Public Function Product ()
{
MX. Events. eventdispatcher. initialize ( This );
}
Public Function Getproductsbycategoryid (categoryid: Number): void
{
VaR XML: XML = New XML ();
XML. ignorewhite = True ;
XML. Load ( " Data/products. xml " );
VaR Self = This ;
XML. onload = Function (Suc)
{
If (Suc)
{
// Product Set
VaR Items: Array = New Array ();
VaR Nodes = This . Firstchild. childnodes;
For ( VaR I: Number = 0 ; I < Nodes. length; I ++ )
{
VaR Pobj: productinfo = New Productinfo ();
Pobj. productid = Parseint (nodes [I]. Attributes. productid );
Pobj. categoryid = Parseint (nodes [I]. Attributes. categoryid );
Pobj. productname = Nodes [I]. Attributes. productname;
Pobj. Brief = Nodes [I]. Attributes. Brief;
Pobj. Detail = Nodes [I]. Attributes. detail;
Pobj. Image = Nodes [I]. Attributes. image;
Pobj. Price = Parseint (nodes [I]. Attributes. Price );
Pobj. adddate = Nodes [I]. Attributes. marketdate;
Items [I] = Pobj;
// Trace (pobj. productname );
}
// Broadcast product loading success events
VaR Eventobj: Object = {Target: Self, type: " Loaded " , ArgS: Items };
Self. dispatchevent (eventobj );
} Else {
Geturl ( " Errorpage.htm " );
}
};
}
}
As on the FLA file:
Stop ();
_ Global. Product = New Usstore. businessobj. Product ();
VaR Loadobj: Object = New Object ();
Loadobj. Loaded = Function (Eventobj)
{
VaR Items: Array = Eventobj. ARGs;
For ( VaR I = 0 ; I < Items. length; I ++ )
{
_Root.txt show. Text + = Items [I]. productname;
}
};
_ Global. Product. addeventlistener ( " Loaded " , Loadobj );
_ Global. Product. getproductsbycategoryid ();