topical media & game development

talk show tell print

professional-flex-code-18-CallLaterExample.mx

professional-flex-code-18-CallLaterExample.mx [swf] flex


  <?xml version="1.0"?>
  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    initialize="applicationInit(event)">
    <mx:Script>
      <![CDATA[
        import mx.collections.ArrayCollection;
            
        [Bindable] private var gridArrayCollection:ArrayCollection;
          
        private function applicationInit(event:Event):void 
        {
          gridArrayCollection = new ArrayCollection();
        }
          
        private function addGridItem(event:Event):void 
        {
          var nameObject:Object = new Object();
          nameObject.firstName = FirstNameInput.text;
          nameObject.lastName = LastNameInput.text;
          gridArrayCollection.addItem(nameObject);
          callLater(selectNewRow);
        }
          
        private function selectNewRow():void 
        {
          nameGrid.selectedIndex = nameGrid.rowCount;
        }
          
      ]]>
    </mx:Script>
       
    <mx:Panel title="callLater Grid Example" width="50%" height="50%" 
      paddingTop="10" paddingLeft="10" 
      paddingRight="10" paddingBottom="10">
      <mx:HDividedBox width="100%" height="100%">
        <mx:Canvas width="100%" height="100%">
          <mx:DataGrid id="nameGrid" dataProvider="{gridArrayCollection}" 
            width="100%" height="100%">
            <mx:columns>
              <mx:DataGridColumn dataField="firstName" 
                headerText="First Name"/>
              <mx:DataGridColumn dataField="lastName" 
                headerText="Last Name"/>
            </mx:columns>
          </mx:DataGrid>
        </mx:Canvas>
  
        <mx:VBox width="70%" height="100%">
          <mx:Label text="First Name:" />
          <mx:TextInput id="FirstNameInput" />
          <mx:Label text="Last Name:" />
          <mx:TextInput id="LastNameInput" />
          <mx:Button label="Enter New Item" click="addGridItem(event)"/>
        </mx:VBox>
      </mx:HDividedBox>
    </mx:Panel>
  </mx:Application>
  


(C) Æliens 04/09/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.