haxe.io.Bytes and ByteArray

709 views
Skip to first unread message

tom rhodes

unread,
Jun 9, 2012, 12:37:17 PM6/9/12
to haxe...@googlegroups.com
Hi,

can i use Bytes where in AS3 a ByteArray is used? i've been posrting stuff using Array<Int> so far but now i'm thinking i've made a big mistake ;)

cheers,

tom.

Simon Krajewski

unread,
Jun 9, 2012, 1:00:10 PM6/9/12
to haxe...@googlegroups.com
Bytes.getData() will give a BytesData object, which is typedeffed to
ByteArray on flash platform. You cannot use Bytes directly where
ByteArray is expected, but Bytes.getData() should make it work.

Simon

Cambiata

unread,
Jun 9, 2012, 1:12:28 PM6/9/12
to haxe...@googlegroups.com
@Simon:
With Sam's answer here https://groups.google.com/d/msg/haxelang/5jiJHm4N8no/IcJZDN3Ese8J as a starting point,
would it be possible, using som macro magic, to create a flash implementation of Bytes that transparently could switch
between Alchemy Memory or ByteArray?

tom rhodes

unread,
Jun 9, 2012, 1:13:04 PM6/9/12
to haxe...@googlegroups.com
i'm going from as3 and trying to make this cross platform.

this is the type of thing in AS3 that makes me want to use Bytes in haxe...

// packed fields
out.writeByte((0x80 | // 1 : global color table flag = 1 (gct used)
     0x70 | // 2-4 : color resolution = 7
     0x00 | // 5 : gct sort flag = 0
     palSize)); // 6-8 : gct size
out.writeByte(0); // background color index
out.writeByte(0); // pixel aspect ratio - assume 1:1

if out becomes Bytes, can this be translated as...

// packed fields
out.set((0x80 | // 1 : global color table flag = 1 (gct used)
    0x70 | // 2-4 : color resolution = 7
    0x00 | // 5 : gct sort flag = 0
    palSize, out.length)); // 6-8 : gct size
out.set(0, out.length); // background color index
out.set(0, out.length); // pixel aspect ratio - assume 1:1

or am i really badly getting this wrong :P

tom rhodes

unread,
Jun 9, 2012, 1:17:51 PM6/9/12
to haxe...@googlegroups.com
ooops, sorry got pos and v the wrong way round in the translation attempt, hopefully you get the idea!

Simon Krajewski

unread,
Jun 9, 2012, 2:04:01 PM6/9/12
to haxe...@googlegroups.com
Am 09.06.2012 19:13, schrieb tom rhodes:
i'm going from as3 and trying to make this cross platform.

this is the type of thing in AS3 that makes me want to use Bytes in haxe...

// packed fields
out.writeByte((0x80 | // 1 : global color table flag = 1 (gct used)
     0x70 | // 2-4 : color resolution = 7
     0x00 | // 5 : gct sort flag = 0
     palSize)); // 6-8 : gct size
out.writeByte(0); // background color index
out.writeByte(0); // pixel aspect ratio - assume 1:1

if out becomes Bytes, can this be translated as...

// packed fields
out.set((0x80 | // 1 : global color table flag = 1 (gct used)
    0x70 | // 2-4 : color resolution = 7
    0x00 | // 5 : gct sort flag = 0
    palSize, out.length)); // 6-8 : gct size
out.set(0, out.length); // background color index
out.set(0, out.length); // pixel aspect ratio - assume 1:1

or am i really badly getting this wrong :P

Why aren't you just using haxe.io.BytesOutput?

Simon

Simon Krajewski

unread,
Jun 9, 2012, 2:09:24 PM6/9/12
to haxe...@googlegroups.com
Not sure I understand, but you can make a implementation for BytesData
which writes to flash.Memory and then switch using conditional compilation.

Simon

tom rhodes

unread,
Jun 9, 2012, 2:10:54 PM6/9/12
to haxe...@googlegroups.com
"Why aren't you just using haxe.io.BytesOutput?"

i don't know :) that's why i'm asking what's best to do here :)

cheers for the tip i'll have a look now...

tom rhodes

unread,
Jun 9, 2012, 2:11:50 PM6/9/12
to haxe...@googlegroups.com
http://haxe.org/api/haxe/io/bytesoutput

can't see any writeByte, writeBytes equivalents in there?

Simon Krajewski

unread,
Jun 9, 2012, 2:13:15 PM6/9/12
to haxe...@googlegroups.com
Am 09.06.2012 20:11, schrieb tom rhodes:
> http://haxe.org/api/haxe/io/bytesoutput
>
> can't see any writeByte, writeBytes equivalents in there?
>

"extends Output": http://haxe.org/api/haxe/io/output ;)

Simon

tom rhodes

unread,
Jun 9, 2012, 2:23:47 PM6/9/12
to haxe...@googlegroups.com
ha! RTFM. sweet, thanks Simon :)



Simon

Reply all
Reply to author
Forward
0 new messages