Menu:

Sponsor

Discover Master of Alchemy, our first iPad/iPhone and iPod touch game!

Follow Me

 

Forum's topics

Latest Files

Archives

Top Rated

Categories

Photo Gallery


Alessandro Crugnola on July 11, 2008 in amfphp

AMFPHP issue referencing ByteArray

Recently I made some test in AMFPHP sending an retrieving ByteArray to be stored in a mysql blob field.
But suddenly I encounter a problem when I was trying to return an array of ByteArrays and I could not find out the reason flash continued to show me this error:

The php file which was generating this error was:

<?

class Service
{	
	public function getArray( )
	{
		$GLOBALS['amfphp']['encoding'] = 'amf3';
		
		$a = new ByteArray("\x00\x10this is a string");
		$b = new ByteArray("\x00\x16this is another string");
		$c = $a;
		return array( $a, $b, $c );
	}
}

?>

While the Actionscript test class was:

package {
	import flash.display.Sprite;
	import flash.net.NetConnection;
	import flash.net.ObjectEncoding;
	import flash.net.Responder;
	import flash.utils.ByteArray;

	public class test extends Sprite
	{
		private var nc: NetConnection;
		private var rsp: Responder;
		
		public function test()
		{
			rsp = new Responder( onResult, null );
			
			nc = new NetConnection( );
			nc.objectEncoding = ObjectEncoding.AMF3;
			nc.connect("http://localhost/amfphp/trunk/gateway.php");
			nc.call("test.bytearray.Service.getArray", rsp );
		}
		
		private function onResult( e: * ): void
		{
			if( e is Array )
			{
				for each( var b: ByteArray in ( e as Array ) )
				{
					trace('reading bytearray...');
					b.position = 0;
					trace( b.readUTF( ) );
				}
			}
		}
	}
}

After some investigation I found that the error was into the AMFSerializer.php file in the writeAmf3ByteArray method which doesn't reference correctly the bytearray objects.
Thus I made a little modification and after that I succeeded to retrieve correctly the bytearray list ( with the 3rd element as reference of the first one ).

Here you can download the patch file, if you want to test the modification ( at your own risk :) ). The patch has been created using the last svn version of amfphp and you can apply the patch with the following command:

patch -p0 -i bytearray.patch

 

Bookmark and Share

 

Tags: actionscript , amfphp , bytearray , reference , svn 

 

7 comments
Alessandro, Thanks for the informative post and patch, it appears to resolve my problem which had slightly different symptoms. In my case, I was returning an array of objects, each with several vars; the bytearray being roughly the middle var. The bytearrays were all returned properly, but the vars after the bytearray were garbled. Anyways, thanks again! Of note, this patch requires you to disable php_amf.dll as the bug appears to be resident in there as well. I'll ping Wade Daly (of amfphp.org) to see if this is relevant in his Zend work and any plans to update php_amf.dll dp
Wow looks like someone didn't do a code review before committing :P I kept wondering why my Flash devs could only cast the return to a String and not a ByteArray! You just saved me from a LOT of pain; thanks!
hello, i have one trouble, when php5 is running the error "Fatal error: Class 'ByteArray' not found " always appears on browser. where can be downloaded ByteArray class or if i miss some php setting? thx lot :)

Hi Alessandro,

I'm trying to send an array of objects contaning a ByteArray from amfphp to flex and it doesn't work, i tried to patch the AMFSerializer.php file but nothing changes, do you have any clue?

I'm trying something like that:

[php]
/////object Employe
class Employe{

var $photo;

function Employe(){

}

function getPhoto()
{
$this->photo = new ByteArray(file_get_contents("image.jpeg"));
}

}

//// the service class
class Service{

function getAllEmploye()
{
$a = array();
for($i=0;$i<10;$i++){
$e = new Employe();
$e->getPhoto( );
array_push($a, $e);
}

return $a;
}

}
[/php]

Flex keep showing me the same error : "didn't receive an acknowledge message"

If you have any idea :)

When calling amfphp from an actionscript only project (not flex) using NetConnection you must force AMFPHP to use the amf3 encoding otherwise you cannot receive a ByteArray class instance.
Hey! So you did my problem that I posted on the forums. So you were able to return a single ByteArray too? I had to do the Base64 thing...


Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Type the characters you see in the picture above.





 

TrackBacks

TrackBack URL for this entry: http://www.sephiroth.it/cgi-bin/mt/mt-tb.cgi/248