2 Replies Latest reply on Jan 29, 2010 9:13 AM by Otuyelu

    Interpreting exercise 3

    bertbaeck

      I have a few question interpreting the code below (exercise 3):

       

      a. In the header <mx:Application ... > a call to init() is made.  By init(), the variable "rooms" is reset

       

      b. in <mx:HTTPService id="rooms" url="assets/roomList.xml"  fault="httpFaultHandler(event)" result="httpResultHandler(event)"/>

          rooms is loaded from the XML file roomList.XML and rooms becomes the input of roomsList (=Array).

       

      How do we know that init() comes first?  Does actionScript doesn't parse code sequentially like for example C++ code?

       

      Thanks for the insight.

       

       

      =====>>>>>>>> CODE LISTING =========>>>>>>>>>>>>

       

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

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#FFFFFF" creationComplete="init()">

       

       

      <mx:Script>

      <![CDATA[

      import mx.events.ListEvent;

      import mx.collections.ArrayCollection;

      import mx.rpc.events.FaultEvent;

      import mx.controls.Alert;

      import mx.rpc.events.ResultEvent;

      [Bindable]private var roomList:ArrayCollection;
      private function changeHandler(event:ListEvent):void{}

       

      private function init():void { rooms.send(); }

       

      private function httpFaultHandler(event:FaultEvent):void { Alert.show("There was a problem","Error"); }

       

      private function httpResultHandler(event:ResultEvent):void { roomList = event.result.rooms.room; }

      ]]>

      </mx:Script>

       

       

      <mx:HTTPService id="rooms" url="assets/roomList.xml"  fault="httpFaultHandler(event)" result="httpResultHandler(event)"/>

       

      <mx:Label text="XYZ Convention Center"  x="10" y="10" fontSize="21" fontWeight="bold"/>

      <mx:Text x="10" y="41" text="111 49th Ave, Denver, CO 80634"/>

      <mx:Text text="Phone: 303-555-1212" x="208" y="41"/>

      <mx:Text text="Fax: 303-555-1234" x="345" y="41"/>

      <mx:Label text="Room Reservation System" fontWeight="bold" fontSize="14" x="10" y="72"/>

      <mx:Label text="Room Available:" x="10" y="108"/>

       

      <mx:List x="10" y="134" id="dg" width="250" itemClick="changeHandler(event)" dataProvider="{roomList}" labelField="name">

      </mx:List>

       

      </mx:Application>