topical media & game development

talk show tell print

lib-flex-store-flexstore.mx

lib-flex-store-flexstore.mx (swf ) [ flash ] flex


  <?xml version="1.0" encoding="utf-8"?>
  <!--
  
//////////////////////////////////////////////////////////////////////////

// // Copyright (C) 2003-2006 Adobe Macromedia Software LLC and its licensors. // All Rights Reserved. // The following is Sample Code and is subject to all restrictions on such code // as contained in the End User License Agreement accompanying this product. // If you have received this file from a source other than Adobe, // then your use, modification, or distribution of it requires // the prior written permission of Adobe. //
//////////////////////////////////////////////////////////////////////////

-->

application


  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
      layout="absolute" minWidth="990" minHeight="550"
      preinitialize="loadStyle()"
      creationComplete="startService()"
      pageTitle="FlexStore">
  
  

script


      <mx:Script>
      <![CDATA[
          import mx.collections.IViewCursor;
          import mx.collections.ArrayCollection;
          //import samples.flexstore.Product;
          import mx.rpc.events.ResultEvent;
          import mx.events.StyleEvent;
          import mx.styles.StyleManager;
  
          [Bindable]
          private var catalog:ArrayCollection;
  
          private var currentTheme:String = "lib-flex-store-beige";
  
  

style toggle(s)


  
          private function toggleTheme():void
          {
              if (currentTheme == "beige")
              {
                  currentTheme = "blue";
              }
              else
              {
                  currentTheme = "beige";
              }
  
              loadStyle();
          }
  
  

service(s) / product(s)


          private function startService():void
          {
              productService.send();
          }
  
          private function loadStyle():void
          {
              var eventDispatcher:IEventDispatcher =
                  StyleManager.loadStyleDeclarations("lib-flex-store-" + currentTheme + ".swf");
              eventDispatcher.addEventListener(StyleEvent.COMPLETE, completeHandler);
          }
  
          private function completeHandler(event:StyleEvent):void
          {
              image.source = acb.getStyle("storeLogo");
              homeView.updateMapImage();
              super.initialized = true;
          }
  
  

result(s)


          private function productServiceResultHandler(event:ResultEvent):void
          {
              //HTTPService returns an ArrayCollection for nested arrays
              var products:ArrayCollection = event.result.catalog.product;
              var temp:ArrayCollection = new ArrayCollection();
              var cursor:IViewCursor = products.createCursor();
              while (!cursor.afterLast)
              {
                  var product:lib_flex_store_samples_flexstore_Product = new lib_flex_store_samples_flexstore_Product();
                  product.fill(cursor.current);
                  temp.addItem(product);
                  cursor.moveNext();
              }
              catalog = temp;
          }
  

beware(s)


  
  /*
          override public function set initialized(value:Boolean):void
          {
              // Hold off until the Runtime CSS SWF is done loading.
          }
  */
      ]]>
      </mx:Script>
  
  

declaration(s)


  
      <mx:Style source="lib-flex-store-main.css"/>
  
      <mx:HTTPService id="productService" url="lib-flex-store-data-catalog.xml"
          result="productServiceResultHandler(event)"/>
  
  

control bar


  
      <mx:VBox width="990" paddingLeft="0" paddingRight="0" horizontalCenter="0" top="12">
  
          <mx:ApplicationControlBar id="acb" width="100%" styleName="storeControlBar">
              <mx:Image id="image" 
                        click="toggleTheme()"
                        toolTip="Change Theme"/>
              <mx:ToggleButtonBar
                  height="100%"
                  dataProvider="{storeViews}"
                  styleName="storeButtonBar"/>
          </mx:ApplicationControlBar>
  
          <!-- using a creationPolicy of "auto" or "queued" has a bug at time of writing
               that prevents initial states from applying styles correctly.
               plus the instantiation of the cart view can cause a performance
               hiccup which we might prefer at startup -->
  

viewstack(s) / page(s)


          <mx:ViewStack id="storeViews" width="100%" height="550" creationPolicy="all">
              <lib_flex_store_HomeView id="homeView" label="Home"
                  showEffect="WipeDown" hideEffect="WipeUp"
                  />
              <lib_flex_store_ProductsView id="pView" label="Products" catalog="{catalog}"
                  showEffect="WipeDown" hideEffect="WipeUp"
                  />
              <lib_flex_store_SupportView id="supportView" label="Support"
                  showEffect="WipeDown" hideEffect="WipeUp"
                  />
          </mx:ViewStack>
  

custom debug/toggle(s)


          <mx:HBox>
          <mx:Button label="style"    click="toggleTheme()" />
          <mx:TextArea text="debug" />
          </mx:HBox>
  
      </mx:VBox>
  
  </mx:Application>
  


(C) Æliens 18/6/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.