4 Replies Latest reply on Nov 2, 2008 4:29 PM by Sunil Guttula

    How to use events to control the calling sequence with data loading component

    JZBAO Level 1
      I created a data loading component TimestampManager.mxml, which retrieve a server timestamp from http://www.XYZ.com/timestamp.php

      timestamp.php
      ---------------------
      <?php
      $timezone = "TZ=US/Central";
      putenv($timezone);
      $Return = "<timestamp>".date("m/d/Y H:i:s", time())." US CST"."</timestamp>";
      print($Return);
      ?>

      TimestampManager.mxml:
      --------------------------------------
      <?xml version="1.0" encoding="utf-8"?>
      <mx:UIComponent xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="timestampService.send()">
      <mx:Script> <![CDATA[
      import mx.rpc.events.ResultEvent;
      public function getTimestamp():String {
      return timestampService.lastResult.timestamp;
      }
      private function serviceResult(event:ResultEvent):void {
      trace(timestampService.lastResult.timestamp);
      }
      ]]> </mx:Script>

      <mx:HTTPService id="timestampService" url=" http://www.XYZ.com/timestamp.php"
      result="serviceResult(event)" useProxy="false" method="POST" />
      </mx:UIComponent>

      I have an application called Footer.mxml, which uses the TimestampManager.mxml to get server timestamp:

      Footer.mxml:
      -------------------
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:mgr="com.XYZ.managers.*" layout="absolute" height="30" width="797">
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="797" height="30" backgroundColor="#05075C" y="0" >
      <mx:Label id="timestamp" text="{tsMgr.getTimestamp()}" color="#FEFEFE" height="20" y="10" textAlign="left" width="224" x="60"/>
      </mx:Canvas>
      <mgr:TimestampManager id="tsMgr"/>
      </mx:Application>

      The problem I have is that the application Footer.mxml calls the component TimestampManager.mxml to get the timestamp before TimestampManager.mxml retrieves the data from timestamp.php on the server. I'm not sure how to control the calling sequence:

      1st: The component TimestampManager.mxml calls timestamp.php on the server first to get the timestamp;
      2nd: The application Footer.mxml calls the component TimestampManager.mxml to display the timestamp.

      Thanks