Archive for the ‘AMFPHP’ Category

Using AMF and RemoteObject without services-config.xml

Saturday, January 23rd, 2010

This article will be very short but I hope it will be very useful. The goal of this article is to show you how to use a RemoteObject without service-config.xml. The example in this post will be very simple, we will connect to a AMFPHP service and get a hello message from it.

First let’s see the service:

1
2
3
4
5
6
7
8
9
10
11
<?php
// hello.php
class Hello
{
	public function sayHello()
	{
		return "Hello back!";
	}
}
 
?>

Now in Flex all we have to do is to load a XML file ( channel.xml ) and read the channel from it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
protected function addedToStageHandler( event :Event ) :void
{
 
	var loader :URLLoader = new URLLoader();
	loader.addEventListener( Event.COMPLETE, completeHandler );
	loader.addEventListener( IOErrorEvent.IO_ERROR, ioErrorHandler );
	loader.load( new URLRequest( "channel.xml" ));
 
}
 
protected function completeHandler( event :Event ) :void
{
 
	// Load info from XML
	var xml :XML = new XML( event.target.data );
	var amfEndpoint :String = xml..channel.( @id == "my-amfphp" ).@endpoint;
 
 
	// Create a AMF channel
	var channel :AMFChannel = new AMFChannel( "my-amf", amfEndpoint );
 
 
	// Add channel to our RemoteObject
	rmtObj.channelSet = new ChannelSet();
	rmtObj.channelSet.addChannel( channel );
 
}

Now if you use the loaded channel for all your RemoteObjects you don’t have to compile again your application if you decide to change your AMF endpoint, all you have to do is to edit the channel.xml file.

This is very useful when you upload your application to a server, you don’t have to compile again the application to work on different servers all you have to do is to use different channel.xml.

You can download the code here ( click to download ).

And this is all. If you have any questions post them here.

AS3FlexDB and UTF8

Saturday, January 31st, 2009

Becouse I’ve received a lot of emails asking me how can AS3FlexDB can select UTF8 data from MySQL i have decided to write a post and explain how you can load UTF8 data from MySQL in Flex.

There are three steps you must done to accomplish this:

Step 1

Setup your MySQL table fields to support UTF8. You can do this by changing your collation to utf8_general_ci 

utf8_table_sample1

Step 2

Edit the AS3FlexDB service ( database.php ) on function open($strUser, $strPass, $strHost) line 37  after 

$rsConnectionID = @mysql_connect($strHost, $strUser, $strPass);

 add 

mysql_set_charset(’utf8′, $rsConnectionID);

this function will set UTF8  character set for the current connection.

Step 3

Edit AMFPHP gateway.php file. The gateway.php file is the bridge between your flash .swf file and AS3FlexDB service (database.php). In this file all you need to change is the setCharsetHandler method.

Replace :

$gateway->setCharsetHandler(”utf8_decode”, “ISO-8859-1″, “ISO-8859-1″);

with :

$gateway->setCharsetHandler( “none”, “ISO-8859-1″, “ISO-8859-1″ );

and this is all. If you have done everything right you can now load UTF8 data from MySQL. 
If you want to read more about  character set in AMFPHP you can check this tutorial.