Skip to content


AMFPHP and Lee Brimelow

Even though I am not a PHP programmer, I was fortunate enough to attend the PHP User Group meeting last night here in Burlington, Vermont to listen to Lee Brimelow discuss the future of AMFPHP. His talk has opened up some new ideas for me and my future Flex, Flash and AIR projects. For now, I just wrote up a simple demo with AMFPHP.

Please check out:

http://www.gotoandlearn.com/player.php?id=78
http://amfphp.org/

package
{
	import flash.display.Sprite;
	import flash.net.*;
	import fl.controls.TextArea;
	import fl.controls.ScrollPolicy;
	import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFieldType;
    import flash.text.TextFormat;  

	public class HelloWorld extends Sprite
	{
		private var output:TextArea;

		public function HelloWorld()
		{
			// show the textfield for output
			ui();

			// setup the connection
			var gw:NetConnection = new NetConnection();
			gw.connect ("http://www.mysite.com/amfphp/gateway.php");

			// 2 functions called on when data is passed back..
			// one function for success, one for failure
			var res:Responder = new Responder(onResult, onFault); 

			// the php method, the result, parameters
			gw.call ("HelloWorld.HelloWorldTest", res, "- AMFPHP is cool!");
		}

		private function onResult(responds:Object):void
		{
			output.appendText ( "PHP Response: " + responds );
		}

		private function onFault(responds:Object):void
		{
			// print out all properties in the object
			for ( var i in responds )
			{
				trace ( responds[i] );
			}
		}

		// UI elements
        private function ui():void
        {
            // Small Black Text Formatting
            var smallBlackFormat:TextFormat = new TextFormat();
            smallBlackFormat.font = "Arial";
            smallBlackFormat.color = 0xffffff;
            smallBlackFormat.size = 10;
            smallBlackFormat.underline = false;    

            // output TextField
            output = new TextArea();
            output.verticalScrollPolicy = ScrollPolicy.ON;
            output.condenseWhite = true;
            output.setSize(700, 100);
            output.move(0,50);
            addChild(output);
        }
	}
}

Here is the PHP file (service) appropriately named HelloWorld.php:

class HelloWorld
{
	/**
	* Demo HelloWorld
	* @returns HelloWorld type
	*/

	function HelloWorldTest($append) // this is what gets called from flash
	{
		$output = "Hello World ".$append;
		return $output;
	}
}

Posted in AMFPHP, Actionscript 3.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.