but are you able to just cast the result?
Code:var result: ByteArray = event.result as ByteArray;
I have a ByteArray in my project that I compress then upload to AMFPHP service which stores the parameter (ByteArray) as a Blob in a database. There is another function that returns a blob from the database and sends it back. Basically somethg like:
However, when I trace my responder function in AS3, I can't define the parameter as a ByteArray. I thought it must be because the parameter has another field "data" inside it, so I just let it be an object and traced param and param['data']. param is [object Object], and param['data'] is a bunch of odd characters which is supposed to be the ByteArray. However, I am unable to cast it as a ByteArray and then uncompress it.Code:return new ByteArray($BlobFromDatabase);
Browser debugger shows:
(flash.utils::ByteArray)#0
bytesAvailable = 49
endian = "bigEndian"
length = 49
objectEncoding = 3
position = 0
Last edited by k2xl; 5th July 2008 at 00:25.
but are you able to just cast the result?
Code:var result: ByteArray = event.result as ByteArray;
TypeError: Error #1034: Type Coercion failed: cannot convert Object@1312921 to flash.events.Event.
Plus, the object does not have a result property.
I'm writing pure AS3 (no mxml)... am I supposed to import ResultEvent or something? where can I download ResultEvent.as? (I'm on Flex Builder 3)
Last edited by k2xl; 5th July 2008 at 18:56.
yes, you don't need the result event.
but I dont understand because you said that the debugger show you:
Browser debugger shows:
(flash.utils::ByteArray)#0
bytesAvailable = 49
endian = "bigEndian"
length = 49
objectEncoding = 3
position = 0
this is the bytearray itself ( the data field ). BTW, are you using Flex builder? or are you debugging with fdb? what's the debugger stack trace?
I'm debugging with AMFPHP's browser folder and calling functions and listening to results.
I don't know what you mean by debugger stack trace (you don't mean trace(new Error().getStackTrace()); do you?)
no, I was meaning the command line debugger:
http://livedocs.adobe.com/flex/201/h...ng_126_03.html
First let me post some code just to be sure I'm doing this right.
Then I have a functionCode:// sMessage is bytearray function insertData($sMessage) { $sMessage = $sMessage->data; $con = mysql_connect("localhost","root",""); $db = mysql_select_db("db"); $sql = "insert into testtable(datafield) values('$sMessage')"; $OK = mysql_query($sql); }
If that looks OK then I'll download the FDBCode:function getData($id) { $con = mysql_connect("localhost","root",""); $db = mysql_select_db("db"); $sql = "select datafield from testtable where id=$id"; $OK = mysql_query($sql); $OK = mysql_fetch_array($OK); $ba = $OK['stringer']; return new ByteArray($ba); }
yes, that's correct
I'm having trouble getting the command line debugger to work... Is there anyway I can print the debugger stack trace with Flex Builder 3? Can you think of any reason why this would be happening?
I'm using XAMPP btw, to simulate PHP and MySQL on my local machine, would that cause a problem?
Also, the variable that's returned has the value data "xÚÁÀ0\b°2µ×ÿ—&»ßÌ„ )VT1é" (qualified class name is String... not ByteArray, and not castable ;-()
And last thing, I'm using TinyBlob type in the database (not regular blob) , I don't know if that makes a difference.
Last edited by k2xl; 6th July 2008 at 18:54.
Just wanted to post that I found ONE solution.
Instead of writing
I write:Code:return new ByteArray($ba);
Then I use this class http://dynamicflash.com/goodies/base64/ and doCode:return new ByteArray(base64_encode($ba));
Then everything seems to work. However, this is not a great solution when compressing and decompressing.Code:level.destory(); var MyData:String = loadedlevel.data; var BA:ByteArray = Base64.decodeToByteArray(MyData); BA.position = 0; BA.uncompress();
My normal byte array was 58 bytes. I compress it and it's 49 bytes. Now I sent it over to the server and the server stores it in a tinyblob and it's 49 bytes per row. Here's the problem, when I retrieve it from the database, it's still 49 bytes; however, the php function base64_encode($string) makes the data 68 bytes instead of an ideal 49 bytes...
What's strange is that the writeUTFBytes (which is what the AS3 Base64.encode function does) doesn't produce the same output as the PHP version's base64_encode, as I can't do the base64 encoding client side...
Last edited by k2xl; 6th July 2008 at 19:58.
Bookmarks