| <?xml version="1.0" encoding="utf-8"?> |
| <!-- |
| |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| |
| --> |
| <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" |
| layout="absolute" minWidth="990" minHeight="550" |
| preinitialize="loadStyle()" |
| creationComplete="startService()" |
| pageTitle="FlexStore"> |
| |
| <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 = "beige"; |
| |
| private function toggleTheme():void |
| { |
| if (currentTheme == "beige") |
| { |
| currentTheme = "blue"; |
| } |
| else |
| { |
| currentTheme = "beige"; |
| } |
| |
| loadStyle(); |
| } |
| |
| private function startService():void |
| { |
| productService.send(); |
| } |
| |
| private function loadStyle():void |
| { |
| var eventDispatcher:IEventDispatcher = |
| styleManager.loadStyleDeclarations(currentTheme + ".swf"); |
| eventDispatcher.addEventListener(StyleEvent.COMPLETE, completeHandler); |
| } |
| |
| private function completeHandler(event:StyleEvent):void |
| { |
| image.source = acb.getStyle("storeLogo"); |
| homeView.updateMapImage(); |
| super.initialized = true; |
| } |
| |
| 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:Product = new Product(); |
| product.fill(cursor.current); |
| temp.addItem(product); |
| cursor.moveNext(); |
| } |
| catalog = temp; |
| } |
| |
| override public function set initialized(value:Boolean):void |
| { |
| // Hold off until the Runtime CSS SWF is done loading. |
| } |
| ]]> |
| </mx:Script> |
| |
| <mx:Style source="main.css"/> |
| |
| <mx:HTTPService id="productService" url="data/catalog.xml" |
| result="productServiceResultHandler(event)"/> |
| |
| <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 --> |
| <mx:ViewStack id="storeViews" width="100%" height="550" creationPolicy="all"> |
| <HomeView id="homeView" label="Home" |
| showEffect="WipeDown" hideEffect="WipeUp" |
| /> |
| <ProductsView id="pView" label="Products" catalog="{catalog}" |
| showEffect="WipeDown" hideEffect="WipeUp" |
| /> |
| <SupportView id="supportView" label="Support" |
| showEffect="WipeDown" hideEffect="WipeUp" |
| /> |
| </mx:ViewStack> |
| |
| </mx:VBox> |
| |
| </mx:Application> |