+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 10 of 15

Thread: Blob field not casted to ByteArray upon sending to AS3

  1. k2xl is offline Newborn member little-flashed member k2xl is on a distinguished road
    Join Date
    Jul 2008
    Posts
    7

    Blob field not casted to ByteArray upon sending to AS3

    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:

    Code:
    return new ByteArray($BlobFromDatabase);
    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.

    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.

  2. Join Date
    Jan 2002
    Location
    Gavirate - Varese (Italy)
    Age
    36
    Posts
    6,004
    but are you able to just cast the result?

    Code:
    var result: ByteArray = event.result as ByteArray;

    Alessandro Crugnola
    Flash | Net | Python Developer
    http://www.sephiroth.it




  3. k2xl is offline Newborn member little-flashed member k2xl is on a distinguished road
    Join Date
    Jul 2008
    Posts
    7
    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.

  4. Join Date
    Jan 2002
    Location
    Gavirate - Varese (Italy)
    Age
    36
    Posts
    6,004
    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?

    Alessandro Crugnola
    Flash | Net | Python Developer
    http://www.sephiroth.it




  5. k2xl is offline Newborn member little-flashed member k2xl is on a distinguished road
    Join Date
    Jul 2008
    Posts
    7
    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?)

  6. Join Date
    Jan 2002
    Location
    Gavirate - Varese (Italy)
    Age
    36
    Posts
    6,004
    no, I was meaning the command line debugger:
    http://livedocs.adobe.com/flex/201/h...ng_126_03.html

    Alessandro Crugnola
    Flash | Net | Python Developer
    http://www.sephiroth.it




  7. k2xl is offline Newborn member little-flashed member k2xl is on a distinguished road
    Join Date
    Jul 2008
    Posts
    7
    First let me post some code just to be sure I'm doing this right.
    Code:
    // 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);
        }
    Then I have a function
    Code:
    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);
        }
    If that looks OK then I'll download the FDB

  8. Join Date
    Jan 2002
    Location
    Gavirate - Varese (Italy)
    Age
    36
    Posts
    6,004
    yes, that's correct

    Alessandro Crugnola
    Flash | Net | Python Developer
    http://www.sephiroth.it




  9. k2xl is offline Newborn member little-flashed member k2xl is on a distinguished road
    Join Date
    Jul 2008
    Posts
    7
    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.

  10. k2xl is offline Newborn member little-flashed member k2xl is on a distinguished road
    Join Date
    Jul 2008
    Posts
    7
    Just wanted to post that I found ONE solution.
    Instead of writing
    Code:
    return new ByteArray($ba);
    I write:
    Code:
    return new ByteArray(base64_encode($ba));
    Then I use this class http://dynamicflash.com/goodies/base64/ and do
    Code:
    level.destory();
    var MyData:String = loadedlevel.data;
    var BA:ByteArray = Base64.decodeToByteArray(MyData);
    BA.position = 0;
    BA.uncompress();
    Then everything seems to work. However, this is not a great solution when compressing and decompressing.

    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.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts