- Mark as New
- Follow
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
The issue is that you are not getting a channel connection between the AIR app and the server. You have to create ChannelSet and Channel explicitly in the script block of your MXML file.
This section of the doc should help as a reference:
Basically, you need something like the bolded text below in your script block. Note that this is for an app build using model-driven development. The bolded items would be essentially the same though; one small difference that you would reference your DataService object with yourService.channelSet rather than productService.serviceControl.channelSet. The "serviceControl" is the name of the DataService instance in a generated service wrapper and applies only to model-driven development.
<?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" xmlns:OfflineAIRAPP="OfflineAIRAPP.*"
preinitialize="app_preinitializeHandler(event)"
creationComplete="windowedapplication1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import com.adobe.offline.ProductOfflineAdapter;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.messaging.Channel;
import mx.messaging.ChannelSet;
import mx.messaging.channels.RTMPChannel;
import mx.messaging.events.ChannelEvent;
import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
public var myOfflineAdapter:ProductOfflineAdapter;
public function channelConnectHandler(event:ChannelEvent):void
{
productService.serviceControl.autoConnect=false;
}
protected function
app_preinitializeHandler(event:FlexEvent):void
{
var cs:ChannelSet = new ChannelSet();
var customChannel:Channel = new RTMPChannel("my-rtmp",
"rtmp://localhost:2037");
cs.addChannel(customChannel);
productService.serviceControl.channelSet=cs;
customChannel.addEventListener(ChannelEvent.CONNECT,
channelConnectHandler);
}
protected function dataGrid_creationCompleteHandler(event:FlexEvent):void
{
getAllResult.token = productService.getAll();
}
protected function
windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
productService.serviceControl.autoCommit = false;
productService.serviceControl.autoConnect = false;
productService.serviceControl.autoSaveCache = false;
productService.serviceControl.offlineAdapter = new
ProductOfflineAdapter();
productService.serviceControl.fallBackToLocalFill=true;
productService.serviceControl.encryptLocalCache = true;
productService.serviceControl.cacheID = "myOfflineCache";
}
protected function connectBtn_clickHandler(event:MouseEvent):void
{
productService.serviceControl.connect();
}
protected function DisconnectBtn_clickHandler(event:MouseEvent):void
{
productService.serviceControl.disconnect();
}
protected function commitBtn_clickHandler(event:MouseEvent):void
{
productService.serviceControl.commit();
}
protected function saveCacheBtn_clickHandler(event:MouseEvent):void
{
productService.serviceControl.saveCache();
}
]]>
</fx:Script>
<fx:Declarations>
<s:CallResponder id="getAllResult" />
<OfflineAIRAPP:ProductService id="productService"
fault="Alert.show(event.fault.faultString + '\n' +
event.fault.faultDetail)"/>
</fx:Declarations>
<mx:DataGrid editable="true" x="9" y="10" id="dataGrid"
creationComplete="dataGrid_creationCompleteHandler(event)"
dataProvider="{getAllResult.lastResult}">
<mx:columns>
<mx:DataGridColumn headerText="productid" dataField="productid"/>
<mx:DataGridColumn headerText="description" dataField="description"/>
<mx:DataGridColumn headerText="price" dataField="price"/>
<mx:DataGridColumn headerText="productname" dataField="productname"/>
</mx:columns>
</mx:DataGrid>
<s:Button x="10" y="246" label="Connect" click="connectBtn_clickHandler(event)"
id="connectBtn" width="84" height="30"/>
<s:Button x="112" y="204" label="Save to Local Cache" id="saveCacheBtn"
click="saveCacheBtn_clickHandler(event)" height="30"/>
<s:Button x="110" y="246" label="Commit to Server" id="commitBtn"
click="commitBtn_clickHandler(event)" width="135" height="30"/>
<s:Button x="10" y="204" label="Disconnect" id="DisconnectBtn"
click="DisconnectBtn_clickHandler(event)" height="30"/>
<s:Label x="270" y="204" text="{'Commit Required: ' +
productService.serviceControl.commitRequired}"/>
<s:Label x="270" y="246" text="{'Connected: ' +
productService.serviceControl.connected}"/>
</s:WindowedApplication>