Flash as2 uses eventdispatcher to broadcast events

Source: Internet
Author: User

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.