Sunday, September 13, 2009

services-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<services-config>
<services>
<service id="amfphp-flashremoting-service"
class="flex.messaging.services.RemotingService"
messageTypes="flex.messaging.messages.RemotingMessage">
<destination id="amfphp">
<channels>
<channel ref="my-amfphp"/>
</channels>
<properties>
<source>*</source>
</properties>
</destination>
</service>
</services>

<channels>
<channel-definition id="my-amfphp" class="mx.messaging.channels.AMFChannel">
<endpoint uri="http://localhost/drupal-6.13/services/amfphp" class="flex.messaging.endpoints.AMFEndpoint"/>
</channel-definition>
</channels>
</services-config>

Drupal with flex example

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()" backgroundGradientAlphas="[1.0, 0.71]" backgroundGradientColors="[#060606, #585555]">
<mx:Script>
import mx.controls.*;
import mx.rpc.events.*;
import mx.utils.ArrayUtil;

[Bindable]
public var recipes:Array;

public function init():void
{
getRecipes();
}

public function onFault(event:FaultEvent):void
{
Alert.show(event.fault.faultString, "Error");
}

public function onViewsResult(event:ResultEvent):void
{
recipes = ArrayUtil.toArray(event.result);
}

public function getRecipes():void
{
views.get("recipe_all", ['nid','title','body','changed','filepath']);
img.source='filepath';
}

public function saveRecipe():void
{
var edit:Object;
if (recipes_select.selectedItem) {
edit = recipes_select.selectedItem;
}
else {
edit = new Object;
}

edit.type = "page";

edit.title = dish.text;
edit.body = recipe.text;

if (edit.title == "" || edit.body == "") {
Alert.show("Enter some content", "Error");
}

node.save(edit);
getRecipes();
}

public function onSaved(event:ResultEvent):void
{
Alert.show("Recipe was saved", "Saved");
}

public function newRecipe():void
{
recipes_select.selectedItem = undefined;

dish.text = "";
recipe.text = "";
}
</mx:Script>

<mx:RemoteObject showBusyCursor="true" destination="amfphp" source="views" id="views">
<mx:method name="get" result="onViewsResult(event)" fault="onFault(event)" />
</mx:RemoteObject>

<mx:RemoteObject showBusyCursor="true" destination="amfphp" source="node" id="node">
<mx:method name="save" result="onSaved(event)" fault="onFault(event)" />
</mx:RemoteObject>

<mx:Panel width="500" height="400" layout="absolute" title="Recipes"
horizontalCenter="0" verticalCenter="0" borderStyle="solid" cornerRadius="10"
backgroundColor="#817C7C" backgroundAlpha="0.52" shadowDistance="10" shadowDirection="right" color="#080808" fontWeight="bold" fontSize="10">
<mx:DataGrid x="10" y="3" width="460" id="recipes_select" dataProvider="{recipes}" borderThickness="2" alternatingItemColors="[#FFFFFF, #FFFFFF]" color="#0D85A8" borderStyle="solid" fontWeight="bold">
<mx:columns>
<mx:DataGridColumn headerText="NID" dataField="nid" width="40"/>
<mx:DataGridColumn headerText="Dish" dataField="node_title"/>
</mx:columns>
</mx:DataGrid>

<mx:Label x="10" y="162" text="Dish" color="#010101" fontWeight="bold"/>

<mx:TextInput x="10" y="186" width="460" id="dish" text="{recipes_select.selectedItem.node_title}" themeColor="#009DFF" backgroundColor="#3E3A3A" color="#FFFFFF" fontWeight="bold" fontFamily="Georgia" borderStyle="solid" borderThickness="2"/>

<mx:Label x="10" y="218" text="Recipe" color="#010101" fontWeight="bold"/>

<mx:TextArea x="10" y="242" width="460" height="75" id="recipe" text="{recipes_select.selectedItem.node_revisions_body}" backgroundColor="#3E3A3A" color="#FFFFFF" fontWeight="bold" fontFamily="Georgia" borderStyle="solid" borderThickness="2"/>

<mx:Button x="416" y="328" label="Save" click="saveRecipe()" fillAlphas="[1.0, 1.0]" fillColors="[#272525, #908D8D, #11B1D3, #76DFF5]" color="#FEFDFD"/>

<mx:Button x="358" y="328" label="New" click="newRecipe()" fillAlphas="[1.0, 1.0]" fillColors="[#272525, #908D8D, #11B1D3, #76DFF5]" color="#FEFDFD"/>

</mx:Panel>
<mx:Image id="img" source="" x="10" y="175"/>
</mx:Application>