Example: Saving a node using Adobe Flex

Last updated on
30 April 2025

This code sample demonstrates the simplest way of saving a node using Adobe Flex and Drupal Services.

Note: You must be signed into Drupal through your browser as administrator for this example to work properly.

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.

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="185" width="256">
  <mx:Script>
    <![CDATA[
		
      import mx.controls.*;
      import mx.rpc.events.*;
						
      public function onFault(event:FaultEvent):void{
        Alert.show(event.fault.faultString, "Error");
      }
			
      public function nodeSaveResult(event:ResultEvent):void{
        mx.controls.Alert.show("Node saved", "Success");
      }
			
      public function saveNode():void{

        var nodeObject:Object = new Object();
				
        nodeObject.type = "page";
        nodeObject.nid = nid.text; // set to zero to create new node
        nodeObject.title = title.text;
        nodeObject.body = body.text;
				
        node.save(nodeObject);
				
      }
						
    ]]>
  </mx:Script>
	
  <mx:RemoteObject endpoint="http://localhost/drupal/services/amfphp" showBusyCursor="true" destination="amfphp" source="node" id="node">
    <mx:method name="save" result="nodeSaveResult(event)" fault="onFault(event)"/>
  </mx:RemoteObject>
		
  <mx:Label x="10" y="10" text="Save Node" fontWeight="bold"/>
  <mx:Label x="10" y="38" text="Node ID:"/>
  <mx:Label x="10" y="65" text="Title:"/>
  <mx:Label x="10" y="91" text="Body:"/>
	
  <mx:TextArea x="84" y="64" width="161" height="19" id="title"/>
  <mx:TextArea x="84" y="90" width="161" height="51" id="body"/>
  <mx:TextInput x="84" y="36" text="0" width="44" id="nid"/>
	
  <mx:Button x="159" y="149" label="Save Node" click="saveNode()" />
	
</mx:Application>

Finally, run the Flex application, type in a title and body, then click "Save Node."

You can confirm that the node was saved by checking Drupal in your browser.

Help improve this page

Page status: Not set

You can: