Amfphp

Adobe Flex - My Code is Your Code

Posted in Air, Amfphp, Cairngorm, Flex, Snippets on October 16th, 2008 by Jonnie – 3 Comments

A bunch of code that I tend to re-use and re-use. The contents are listed in the table of contents below.

As changes occur this files will be updated. Keep in mind that this is raw uncut code. So some might be sloppy and some might be clean, some might not work, and some might save your life. ;)

Everything works. Enjoy!

Adobe Air

  1. Connecting to SQLite
  2. Network Connection Manager
  3. SQLite Database Manager
  4. Executing Querys on SQLite
  5. Importing XML into SQLite
  6. Saving Preferences to Local Store
  7. Taking A Screenshot
  8. Update Manager
  9. 30boxes.com API Interface
  10. 30boxes.com API Service
  11. Twitter Amfphp API Service
  12. Del.icio.us API Interface
  13. Del.icio.us API Service
  14. Amfphp Service
  15. Cairngorm Command
  16. Cairngorm Controller
  17. Cairngorm Delegate
  18. Cairngorm Event
  19. Cairngorm Model Locator
  20. Cairngorm Value Object


Adobe Flex

  1. 30boxes.com API Browser
  2. Twitter Amfphp API Browser
  3. Buzznet API Browser
  4. Flex Download Component
  5. Flex Upload Component
  6. Flex Email Component
  7. WordPress API Browser
  8. Service-Config.xml
  9. Del.icious Post Form
  10. Del.icious Post List
  11. Del.icious Post View
  12. Del.icious Tag Form
  13. Del.icious Tag List
  14. Del.icious Tag View
  15. Del.icious User Form
  16. Del.icious User View
  17. Del.icious User Info
  18. Del.icious View


PHP

  1. Amfphp Saving Image
  2. Amfphp Sending Emails
  3. Amfphp CRUD Service
  4. Amfphp DB Connection
  5. Flex File Download
  6. Flex File Upload




Adobe Flex - Amfphp Video Tutorial Part 1

Posted in Amfphp, Flex, Screencasts, Tutorials on October 15th, 2008 by Jonnie – 4 Comments

I put together this little walk through for the visual learners out there. We do the whole process of setting up AMFPHP to creating our server side objects and services. It is a really good thing to watch to get up to speed with Flash Remoting.

We create a application called Flex Contacts, a desktop based contact manager built with Adobe Flex.

There is two parts of this tutorial, part 1 which is the server side and part 2 which covers the client side bringing together another CRUD Flex application using AMFPHP and Flex.

Before you watch the videos here is the source files for both, and make sure you use this SQL before getting started.

   1: CREATE TABLE `contacts` (
   2:   `contact_id` int(11) NOT NULL auto_increment,
   3:   `contact_fname` varchar(200) NOT NULL,
   4:   `contact_lname` varchar(200) NOT NULL,
   5:   `contact_email` varchar(200) NOT NULL,
   6:   `contact_url` varchar(200) NOT NULL,
   7:   PRIMARY KEY  (`contact_id`)
   8: ) TYPE=InnoDB  AUTO_INCREMENT=6 ;

 

Here is the video link and source files for Part 1 (server side)

 

Here is the video link and source files for Part 2 (client side)

 

Here is a working example of what we are going to create.

Adobe Flex - Twitter with Cairngorm and AMFPHP in 10 Minutes

Posted in Amfphp, Flex, Screencasts, Tutorials on October 7th, 2008 by Jonnie – 2 Comments

Here is a really quick fun thing I tried. I took Amfphp, Twitter and the Cairngorm and created an application.

My hand started to cramp and I got really off target at the end.

Check out the video here

Adobe Flex - Creating a Service Class for Amfphp

Posted in Air, Amfphp, Flex, Snippets, Tutorials on September 21st, 2008 by Jonnie – Be the first to comment

Here is a very helpful script for creating a connection between your Flex/Flash application and amfphp.

We are mimicking the available methods that are on our server. You could easily add methods to both ends to create more functionality.

Code is used as follows:

   1: package com.jonniespratley.snippr.services
   2: {
   3:     import com.jonniespratley.snippr.model.ModelLocator;
   4:     import com.jonniespratley.snippr.vo.SnippetVO;
   5:     
   6:     import flash.net.NetConnection;
   7:     import flash.net.Responder;
   8:     import flash.utils.ByteArray;
   9:     
  10:     import mx.collections.ArrayCollection;
  11:     import mx.controls.Alert;
  12:     import mx.controls.Image;
  13:     import mx.controls.Text;
  14:     import mx.core.Window;
  15:     import mx.rpc.events.ResultEvent;
  16:     
  17:     /**
  18:      * This file is for use without! using the services-config.xml file 
  19:      * @author Jonnie
  20:      * 
  21:      */    
  22:     public class SnipprService
  23:     {
  24:         private static var _service:NetConnection;
  25:         private var model:ModelLocator = ModelLocator.getInstance();
  26:         
  27:         //Here we are creating a new connection to our amfphp service, when this is instantiated, it connects to our service
  28:         public function SnipprService()
  29:         {
  30:             _service = new NetConnection();
  31:             _service.connect( "http://localhost/snippr/amfphp/gateway.php" );
  32:         }        
  33:         
  34:         
  35:         /* ***************************************
  36:         *** Service Calls
  37:         *****************************************/
  38:         
  39:         //Here we are calling the getSnippets on our server (amfphp) and setting the result and fault handlers
  40:         public function getSnippets():void
  41:         {
  42:             _service.call( "snippr.SnipprService.getSnippets", new Responder( snippetResultHandler, snipprFaultHandler ) );
  43:         }
  44:         
  45:         //We take one argument here, and that is a snippet, because our server (amfphp) is expecting a snippetVO
  46:         public function saveSnippet( snippet:SnippetVO ):void
  47:         {
  48:             _service.call( "snippr.SnipprService.saveSnippet", new Responder( snippetSavedHandler, snipprFaultHandler ), snippet );
  49:         }
  50:         
  51:         //We take one argument here, and that is the id of the snippet we are wanting to remove
  52:         public function removeSnippet( snippet_id:uint ):void
  53:         {
  54:             _service.call( "snippr.SnipprService.removeSnippet", new Responder( snippetRemoveHandler, snipprFaultHandler ), snippet_id );
  55:         }
  56:         
  57:         //We take two arguments here, one is a byte array and the other is the filename of the file
  58:         public function takeSnapshot( bytes:ByteArray, filename:String ):void
  59:         {
  60:             _service.call( "snippr.SnipprService.takeSnapshot", new Responder( snapshotResultHandler, snipprFaultHandler ), bytes, filename );
  61:         }        
  62:         
  63:         /* ***************************************
  64:         *** Result and Fault Handlers
  65:         *****************************************/
  66:         
  67:         //Here we are handling the result coming back as an array of snippets, then we add our snippets to our model        
  68:         private function snippetResultHandler( data:Array ):void
  69:         {            
  70:             model.snippetCollection = initVO( data );
  71:         }
  72:         
  73:         private function snapshotResultHandler( data:Object ):void
  74:         {
  75:             var result:ResultEvent = data as ResultEvent;
  76:                         
  77:             /* This is just for some fun */
  78:             var w:Window = new Window();
  79:                 w.width = 600;
  80:                 w.height = 500;
  81:                 w.layout = "vertical";
  82:                 
  83:             var i:Image = new Image();                                
  84:                 i.source = data.result;
  85:                 
  86:             var t:Text = new Text();
  87:                 t.text = "Nice shot, and nice app, Here is the link for the screenshot.n " + data.result;
  88:                 
  89:                 w.addChild( i );
  90:                 w.addChild( t );            
  91:                 w.open();            
  92:                 
  93:             trace( data.result );
  94:         }
  95:         
  96:         //Helper for the result
  97:         private function initVO( resultArray:Array ):ArrayCollection
  98:         {
  99:             var tempArray:ArrayCollection = new ArrayCollection();
 100:             
 101:             for ( var s:String in resultArray )
 102:             {
 103:                 tempArray.addItem( new SnippetVO( resultArray[s] ) );
 104:                 
 105:             }
 106:             return tempArray;
 107:         }
 108:         
 109:         //Here we are handling the result and adding it to the value of serviceResponse in our model
 110:         private function snippetSavedHandler( data:Object ):void
 111:         {
 112:             ModelLocator.getInstance().serviceResponse = data.toString();
 113:         }
 114:         
 115:         /*
 116:         Here we are handling the result that is being returned, which will be the id of the removed snippet, and 
 117:         removing it from our model, at the snippet index
 118:         */
 119:         private function snippetRemoveHandler( data:Object ):void
 120:         {
 121:             getSnippets();
 122:         }
 123:         
 124:         //Here we are alerting the user that there was an error connection to our server
 125:         private function snipprFaultHandler( fault:Object ):void
 126:         {
 127:  
 128:             Alert.show( "There was an error connecting to the server.", "Snippr Service Error" );
 129:         }        
 130:     }        
 131: }

 

Here is the value object for this class

SnippetVO.as:

   1: package com.jonniespratley.snippr.vo
   2: {    
   3:     [RemoteClass(alias="vo.SnippetVO")]
   4:     
   5:     /**
   6:      * VOs are used to create a layer of business objects that can be 
   7:      * transferred between tiers, instead of using records, results sets, and datasets.
   8:      */
   9:     [Bindable]
  10:     public class SnippetVO
  11:     {
  12:         public var snippet_id:int;
  13:         public var snippet_title:String;
  14:         public var snippet_code:String;
  15:         public var snippet_type:String;
  16:         public var snippet_created:String;
  17:         public var snippet_user:String;        
  18:         
  19:         /**
  20:          * Helper function for building the data. 
  21:          * @param source
  22:          * 
  23:          */        
  24:         public function SnippetVO( source:Object = null )
  25:         {
  26:             if ( source != null )
  27:             {
  28:                 for ( var item:String in source )
  29:                 {
  30:                     try 
  31:                     {
  32:                         this[item] = source[item];
  33:                     }
  34:                     catch ( error:Error )
  35:                     {
  36:                         throw new Error( "SnippetVO: " + error );
  37:                     }
  38:                 }
  39:             }
  40:         }
  41:     }
  42: }

 

Here is also examples of using this class in a view.

   1: <?xml version="1.0" encoding="utf-8"?>
   2: <!--SnippetList-->
   3: <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="200" height="100%" creationComplete="init()">
   4:  
   5:     <mx:Script>
   6:         <![CDATA[
   7:             import mx.controls.Alert;
   8:             import mx.events.CloseEvent;
   9:             import com.jonniespratley.snippr.services.SnipprService;
  10:             import com.jonniespratley.snippr.vo.SnippetVO;
  11:             import com.jonniespratley.snippr.events.SnippetGetEvent;
  12:             import com.jonniespratley.snippr.model.ModelLocator;            
  13:             
  14:             //Make a instance of our model for our data display
  15:             [Bindable] private var model:ModelLocator = ModelLocator.getInstance();                
  16:             
  17:             //Make a variable to check weither there is a selected snippet or not
  18:             [Bindable] private var isSelected:Boolean = false;
  19:             
  20:             //Make variable of our service
  21:             private var service:SnipprService; 
  22:         
  23:             
  24:             private function init():void
  25:             {
  26:                 service = new SnipprService();
  27:                 getSnippets();
  28:             }
  29:             
  30:             //Send a call to get the snippets
  31:             p