Advertisement
kremisoski

MXML States / Data Binding

Feb 13th, 2015
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MXML 1.68 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
  3.                xmlns:s="library://ns.adobe.com/flex/spark"
  4.                xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init(event)">
  5.    
  6.     <fx:Script>
  7.         <![CDATA[
  8.             //import mx.controls.Alert;
  9.             import mx.events.FlexEvent;
  10.            
  11.             [Bindable]
  12.             private var labelText:String;
  13.            
  14.             [Bindable]
  15.             private var myState:String = currentState;
  16.            
  17.             protected function init(event:FlexEvent):void
  18.             {
  19.                 labelText = "HOME";
  20.                 currentState = "home";
  21.                 myState = currentState;
  22.             }
  23.            
  24.             protected function ezNav(e:MouseEvent):void
  25.             {
  26.                 var nav:String = String(e.target.id);
  27.                 currentState = nav;
  28.                 myState = currentState;
  29.                 labelText = nav.toUpperCase();
  30.                 //Alert.show(nav);
  31.             }
  32.            
  33.         ]]>
  34.     </fx:Script>
  35.    
  36.     <!-- MXML -->
  37.     <s:states>
  38.         <s:State name="home" />
  39.         <s:State name="about" />
  40.         <s:State name="bio" />
  41.     </s:states>
  42.     <s:Panel title="States of Being">
  43.         <s:VGroup>
  44.             <s:HGroup>
  45.                 <s:Button id="home" label="Home" click="ezNav(event)" />
  46.                 <s:Button id="about" label="About" click="ezNav(event)" />
  47.                 <s:Button id="bio" label="Bio" click="ezNav(event)" />
  48.             </s:HGroup>
  49.             <s:Label text="This is the {labelText} page!  This shows up in all states with just the one word changing." />
  50.             <s:Label includeIn="home" text="This only shows up in the {myState} state!" fontSize="30" />
  51.             <s:Label includeIn="about" text="This only shows up in the {myState} state!" fontSize="30" />
  52.             <s:Label includeIn="bio" text="This only shows up in the {myState} state!" fontSize="30" />
  53.         </s:VGroup>    
  54.     </s:Panel>
  55. </s:Application>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement