Hi, in the following code :
var benq:Base64Encoder = new Base64Encoder();
benq.encode("force",0,5);
var tmp:String = benq.toString();
'tmp' turns out to be an empty string, i.e. with length 0. why? how to encode a string using base64encoder?
Hi, in the following code :
var benq:Base64Encoder = new Base64Encoder();
benq.encode("force",0,5);
var tmp:String = benq.toString();
'tmp' turns out to be an empty string, i.e. with length 0. why? how to encode a string using base64encoder?
Are you using Flex 3, as it seems to be a new feature? Also try encoding into a bytearray using encodeBytes and using encodeUTFBytes, perhaps these work better.
Online reference is available from Adobe, but I guess you know that.
Are you sure that your code isn't working. I just copied and pasted it into a test app and it returned tmp as 'Zm9yY2U='
Are you doing anything else to the var tmp? if debugging make sure that it has processed the var tmp:String.... line when your checking the output
<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
creationComplete="but1.label = encodeit()">
<mx:Script>
<![CDATA[
import mx.utils.Base64Encoder;
private function encodeit(): String {
var benq:Base64Encoder = new Base64Encoder();
benq.encode("force",0,5);
var tmp:String = benq.toString();
return tmp;
}
]]>
</mx:Script>
<mx:Button
id="but1"
width="100"
height="100"
/></mx:Application>
Ok, it is working. The code that I posted was different from what I was actually using. I skipped over the fact that calling toString() for Base64Encoder clears its internal buffer. So, calling it the next time would return an empty string. Sorry for the trouble.