Product.as文件

Flash AS2 用EventDispatcher广播事件import USStore.Model.ProductInfo;
Flash AS2 用EventDispatcher广播事件class USStore.BusinessObj.Product
Flash AS2 用EventDispatcher广播事件{
Flash AS2 用EventDispatcher广播事件    public 
var addEventListener:Function;
Flash AS2 用EventDispatcher广播事件    public 
var removeEventListener:Function;
Flash AS2 用EventDispatcher广播事件    private 
var dispatchEvent:Function;
Flash AS2 用EventDispatcher广播事件    
Flash AS2 用EventDispatcher广播事件    public 
function Product() 
Flash AS2 用EventDispatcher广播事件    {
Flash AS2 用EventDispatcher广播事件        mx.events.EventDispatcher.initialize(
this);
Flash AS2 用EventDispatcher广播事件    }
Flash AS2 用EventDispatcher广播事件    public function GetProductsByCategoryID(categoryID:Number):Void 
Flash AS2 用EventDispatcher广播事件    {
Flash AS2 用EventDispatcher广播事件        
var xml:XML = new XML();
Flash AS2 用EventDispatcher广播事件        xml.ignoreWhite 
= true;
Flash AS2 用EventDispatcher广播事件        xml.load("data/products.xml");
Flash AS2 用EventDispatcher广播事件        
var self = this;
Flash AS2 用EventDispatcher广播事件        xml.onLoad 
= function(suc) 
Flash AS2 用EventDispatcher广播事件        {
Flash AS2 用EventDispatcher广播事件            
if(suc) 
Flash AS2 用EventDispatcher广播事件            {
Flash AS2 用EventDispatcher广播事件                
//产品集合
Flash AS2 用EventDispatcher广播事件
                var items:Array = new Array();
Flash AS2 用EventDispatcher广播事件                
var nodes = this.firstChild.childNodes;
Flash AS2 用EventDispatcher广播事件                
for(var i:Number=0; i<nodes.length; i++
Flash AS2 用EventDispatcher广播事件                {
Flash AS2 用EventDispatcher广播事件                    
var pobj:ProductInfo = new ProductInfo();
Flash AS2 用EventDispatcher广播事件                    pobj.ProductID        
= parseInt(nodes[i].attributes.productID);
Flash AS2 用EventDispatcher广播事件                    pobj.CategoryID        
= parseInt(nodes[i].attributes.categoryID);
Flash AS2 用EventDispatcher广播事件                    pobj.ProductName    
= nodes[i].attributes.productName;
Flash AS2 用EventDispatcher广播事件                    pobj.Brief            
= nodes[i].attributes.brief;
Flash AS2 用EventDispatcher广播事件                    pobj.Detail            
= nodes[i].attributes.detail;
Flash AS2 用EventDispatcher广播事件                    pobj.Image            
= nodes[i].attributes.image;
Flash AS2 用EventDispatcher广播事件                    pobj.Price            
= parseInt(nodes[i].attributes.price);
Flash AS2 用EventDispatcher广播事件                    pobj.AddDate        
= nodes[i].attributes.marketDate;
Flash AS2 用EventDispatcher广播事件                    items[i] 
= pobj;
Flash AS2 用EventDispatcher广播事件                    
//trace(pobj.ProductName);
Flash AS2 用EventDispatcher广播事件
                }
Flash AS2 用EventDispatcher广播事件                //广播产品加载成功事件
Flash AS2 用EventDispatcher广播事件
                var eventObj:Object    = {target:self,type:"Loaded",args:items};
Flash AS2 用EventDispatcher广播事件                self.dispatchEvent(eventObj);
Flash AS2 用EventDispatcher广播事件            } 
else {
Flash AS2 用EventDispatcher广播事件                getURL(
"ErrorPage.htm");
Flash AS2 用EventDispatcher广播事件            }
Flash AS2 用EventDispatcher广播事件        };
Flash AS2 用EventDispatcher广播事件    }
Flash AS2 用EventDispatcher广播事件}

fla文件上的as:

Flash AS2 用EventDispatcher广播事件stop();
Flash AS2 用EventDispatcher广播事件_global.Product 
= new USStore.BusinessObj.Product();
Flash AS2 用EventDispatcher广播事件
var loadObj:Object = new Object();
Flash AS2 用EventDispatcher广播事件loadObj.Loaded 
= function(eventObj)
Flash AS2 用EventDispatcher广播事件{
Flash AS2 用EventDispatcher广播事件    
var items:Array = eventObj.args;
Flash AS2 用EventDispatcher广播事件    
for(var i=0;i<items.length;i++)
Flash AS2 用EventDispatcher广播事件    {
Flash AS2 用EventDispatcher广播事件        _root.txtShow.text 
+= items[i].ProductName;
Flash AS2 用EventDispatcher广播事件    }
Flash AS2 用EventDispatcher广播事件};
Flash AS2 用EventDispatcher广播事件_global.Product.addEventListener(
"Loaded",loadObj);
Flash AS2 用EventDispatcher广播事件_global.Product.GetProductsByCategoryID();

相关文章: