开发者

How do you combine two bytearrays in AS3?

I'm trying to combine two ByteArrays to send it out as post data using URLRequest.. Whenev开发者_JAVA技巧er I try to simply add them up, the request becomes GET instead of POST and the data for some reason doesn't get included.


create a total ByteArray by adding other ByteArray objects to it via the writeBytes() public method of the ByteArray class.

more info here: Reading and writing a ByteArray


Combining / Concatination Two Byte Arrays

Var Data:ByteArray = new ByteArray();
Var Salt:ByteArray = new ByteArray();
    var DataAndSalt:ByteArray = new ByteArray();
                    DataAndSalt.length = (Data.length + Salt.length);//Defines the **length of Resultant Array**
                //Array Copy Method(VB)/ Concate the ByteArray(ActionScript) one After another  
                    DataAndSalt.writeBytes(Data);
                    DataAndSalt.writeBytes(Salt);

I will Show here Conversion of String into Byte Array and Merging Them (concate /combining) them into single byte array

// In Detail


            var HashOut:ByteArray = new ByteArray();
            var byterrData:ByteArray = new ByteArray();
            var byterrSalt:ByteArray = new ByteArray();

        //conversion of string Data and Salt in respective (UTF-8 and Default) Byte Array   

     var Data:String = "password";
              var Salt:String ="‰ô©³¶í";  //Using Special Characters in a String variable 

            byterrData.writeMultiByte(Data, "iso-8859-1");
            byterrSalt.writeMultiByte(Salt,Salt);

var DataAndSalt:ByteArray = new ByteArray();
                DataAndSalt.length = (Data.length + Salt.length);
            // Concate the ByteArray    
                DataAndSalt.writeBytes(Data);
                DataAndSalt.writeBytes(Salt);

//Now You can Trace It by using 

trace(DataAndSalt[0]);
trace(DataAndSalt[index Number]);


Not sure what your code looks like... the GET/POST issue is very weird.

However, use the below instead of trying to "add them up" (whatever that means).

array3 = array1.concat(array2);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜