Example: Flagging a Node with Adobe Flex
This code sample demonstrates how to use the flag content methods of the Services module via Adobe Flex.
First ensure you have Drupal installed with the Services and AMFPHP modules properly set up. Refer to this page for more details on how to do this.
You must have the Flag content module installed in order to enable the flag content service. First install the Flag content module and then apply this patch to the Services module to reveal the new services methods.
Before trying to access the service via Flex, ensure you have the proper settings and permissions of the Flag content module set up so that you can flag content through the normal Drupal interface.
Next copy the following MXML code into a new Flex Project and then update the endpoint to point to your AMFPHP gateway:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" height="68" width="244">
<mx:Script>
<![CDATA[
import mx.rpc.events.*;
public function flagNode():void{
flag_content.flag(nodeID.text);
}
public function onFlagNodeResult(event:ResultEvent):void{
mx.controls.Alert.show(event.result.toString(), "Success");
}
public function onFault(event:FaultEvent):void{
mx.controls.Alert.show(event.fault.faultString, "Error");
}
]]>
</mx:Script>
<mx:RemoteObject endpoint="http://localhost/services/amfphp" showBusyCursor="true" destination="amfphp" source="flag_content" id="flag_content">
<mx:method name="flag" result="onFlagNodeResult(event)" fault="onFault(event)"/>
</mx:RemoteObject>
<mx:Label x="10" y="12" text="Node ID:" fontWeight="bold"/>
<mx:TextInput x="74" y="10" width="36" id="nodeID" text="1"/>
<mx:Button x="118" y="10" label="Flag Node" click="flagNode()"/>
</mx:Application>Finally, run the application and test it by choosing a node id to flag.
