3 Replies Latest reply on Jun 15, 2010 2:21 PM by Joshfromdallas

    CACHE DATA FOR OFFLINE USE

    Joshfromdallas Level 1

      I am using Flash Builder 4

       

      I have datagrid that uses a HTTPService php to populate data. I am trying to cache the data so that when the user is not connected to the internet they can pull the last downloaded copy of the datasource. I have done a few searches and returned this page:

       

      http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/lcds/help.html?content=dms_ad vanced_2.html

       

      Which appears to be for livecycle but close to what I need to do. I have been tinkering but get errors. Has anyone seen a good tutorial or have time to walk me through getting it to work.

       

      I have an air application and my code is below:

       

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

      <s:WindowedApplication

       

       

      xmlns:fx="http://ns.adobe.com/mxml/2009"

      xmlns:s="

      library://ns.adobe.com/flex/spark"

      xmlns:mx="

      library://ns.adobe.com/flex/mx"

      minWidth="

      800" minHeight="600"

      title="

      ORDER TEST ver .1 ALPHA"

      xmlns:getorders="

      services.getorders.*"

      creationComplete="loadData()"

       

      >

       

       

      <s:layout>

       

       

      <s:BasicLayout />

       

       

      </s:layout>

       

       

       

      <fx:Style source="Main.css"/>

       

       

      <fx:Script>

      <![CDATA[

       

       

      import mx.collections.ArrayCollection;

       

      import mx.controls.Alert;

       

      import mx.data.DataService;

       

      import mx.events.FlexEvent;

       

      import mx.rpc.events.FaultEvent;

       

      import mx.rpc.events.ResultEvent;

       

       

      protected function getOrders_resultHandler(event:ResultEvent):void

      {

      orders = event.result.orders.order;

      }

       

      [

       

      Bindable]

       

      private var orders:ArrayCollection;

       

       

      private function loadData(){

      techOrders.fill(orders);

      }

       

       

      protected function getOrders_faultHandler(event:FaultEvent):void

      {

      Alert.show(event.fault.faultString,

       

      "Error Information" );

      }

       

      ]]>

       

      </fx:Script>

       

       

      <fx:Declarations>

       

       

      <!-- Place non-visual elements (e.g., services, value objects) here -->

       

       

      <s:HTTPService id="getOrders"

      url=

      http://www.website.com/mods/modsgetorders.php

      result="getOrders_resultHandler(event)"

      fault="getOrders_faultHandler(event)"

       

      >

       

       

      <s:request xmlns="">

       

       

      <techId>

      {techId.text}

       

       

      </techId>

       

       

       

      </s:request>

       

       

      </s:HTTPService>

       

       

      <mx:DataService id="techOrders" destination="D" />

       

       

       

      </fx:Declarations>

       

       

       

      <s:Panel x="0" y="0" width="100%" height="100%" title="TEST SYSTEM">

       

       

       

      <s:Group x="0" y="0" width="100%" height="100%">

       

       

       

      <s:Label x="10" y="14"

      text="

      Username:"

      height="

      25"

      verticalAlign="

      middle"/>

       

      <s:TextInput id="techId"

      x="

      94" y="14"

      width="

      101" height="25" cachePolicy="on"/>

       

      <s:Label x="10" y="43"

      text="

      Password:"

      height="

      25"

      verticalAlign="

      middle"/>

       

      <s:TextInput id="password"

      x="

      94" y="43"

      width="

      101" height="25"/>

       

      <s:Button x="223" y="10"

      label="

      Download Orders"

      click="getOrders.send()"

      height="

      25"

       

      />

       

       

      <mx:Button label="Save"

      click="techOrders.saveCache(ArrayCollection(currentOrders.dataProvider))" x="

      479" y="10"/>

       

      <mx:Button label="Clear"

      click="techOrders.clearCache(ArrayCollection(currentOrders.dataProvider))" x="

      479" y="48"/>

       

       

      </s:Group>

       

      <s:Group x="0" y="87" width="100%" height="100%">

       

      <mx:DataGrid id="currentOrders"

      y="

      0"

      height="

      300"

      dataProvider="

      {orders}"

      dropShadowVisible="

      false"

      editable="

      false"

      right="

      10" left="10"

      cachePolicy="

      on"

      rowCount="

      10">

       

      <mx:columns>

       

      <mx:DataGridColumn headerText="Date Assigned" dataField="date"/>

       

      <mx:DataGridColumn headerText="Order ID" dataField="orderId"/>

       

      <mx:DataGridColumn headerText="Route ID" dataField="routeId"/>

       

      <mx:DataGridColumn headerText="Store ID" dataField="storeId"/>

       

      <mx:DataGridColumn headerText="City" dataField="city"/>

       

      <mx:DataGridColumn headerText="State" dataField="state"/>

       

      </mx:columns>

       

      </mx:DataGrid>

       

       

       

      </s:Group>

       

       

      </s:Panel>

      </s:WindowedApplication>

       

      I have been hacking around in here so some of this may seem screwed up, I apologize just rying to find the missing piece!

       

       

      Thanks for taking the time to read this post and for any suggestions you offer.