<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="this.initApp();" width="401" height="273" viewSourceURL="srcview/index.html">
    <mx:Script>
        <![CDATA[
            
            import com.ericfeminella.products.ProductFactory;
            import com.ericfeminella.products.IProduct;
            import mx.controls.Alert;
            
            private var factory:ProductFactory;

            private function initApp():void 
            {
                this.productList.dataProvider = [{id: "ProductA"},{id: "ProductB"},{id: "ProductC"},{id: "ProductD"}];
            }
            
            private function getProduct(productID:String):void 
            {
                try {
                    var product:IProduct = ProductFactory.getProduct(productID);
                    Alert.show("Instantiated " + product.getName());
                }
                catch(err:Error) 
                {
                    Alert.show(err.message);
                }
            }
        ]]>
    </mx:Script>
    
    <mx:Style source="css/display.css" />
    
    <mx:Label text="ActionScript 3 Factory Pattern implementation:" x="19" y="10" width="361"  height="26"/>
    
    <mx:Panel label="" x="10" y="32" width="381" height="227" layout="absolute">
        <mx:List id="productList" labelField="id" change="this.getProduct(this.productList.selectedItem.id)" x="0" y="117" width="361"  height="90"/>
        <mx:TextArea text="Basic sample application which demonstrates how to implement the Factory Pattern in ActionScript 3.0. Below are a list of products which once selected, can be instantiated by the ProductFactory. ProductD is not a subclass of Product and not provided by the Factory. Therefore it can not be instantiated and will throw an error by the Factory" editable="false" x="0" y="10" width="361" height="99"/>
    </mx:Panel>

</mx:Application>