A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: ByteArray question

  1. #1
    Junior Member
    Join Date
    Aug 2006
    Location
    Tangier (Morocco)
    Posts
    16

    ByteArray question

    hi everybody,

    I'm taking my first steps with AS3 and here is my first problem:

    I want to create a ByteArray from an Array of bytes. Right now I do this:

    Code:
    var embedded_swf: Array = [ 0x46,0x57,0x53,0x09,....
    var swf: ByteArray = new ByteArray();
    for( var i: int = 0 ; i < embedded_swf.length ; i++ )
    {
         swf.writeByte( embedded_swf[i] );
    }
    but I'm not sure if there is a faster way to do the same thing.

    any help would be very appreciated. thanks in advance.

  2. #2
    Member
    Join Date
    May 2007
    Posts
    35
    You can try storing the array as unsigned ints (groups of four bytes) instead:

    Code:
    var embedded_swf: Array = [ 0x46575309,....
    var swf: ByteArray = new ByteArray();
    for( var i: int = 0 ; i < embedded_swf.length ; i++ )
    {
         swf.writeUnsignedInt( embedded_swf[i] );
    }
    or better yet can you just avoid the array all together?

    Code:
    var swf: ByteArray = new ByteArray();
    swf.writeUnsignedInt( 0x46575309 );
    swf.writeUnsignedInt( ... );
    You may have to write some code or a macro or something to reformat your code, but this should run a bit better.

  3. #3
    Junior Member
    Join Date
    Aug 2006
    Location
    Tangier (Morocco)
    Posts
    16
    thanks for your reply.

    finally, what I do is: I stored the embedded swf in a static ByteArray. At runtime, I use ByteArray.writeBytes() to write the whole byte array to the new one. I hope writeBytes() function is faster than a loop that I code myself.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center