03-17-2011 06:04 PM
Hi All,
I am using a FileStream to save a byteArray to the Playbook, however it doesn't seem like any of the events are being fired.
Has anyone else had the same issue?
Regards
Anthony
Solved! Go to Solution.
03-17-2011 06:10 PM
which methods of the filestream class are you trying to use?
03-17-2011 06:14 PM
Where are you trying to save it, specifically, and what events are you listening for? Have you tried the error events too?
03-17-2011 06:14 PM
Hi,
I have used FileStream API and I did not had any issues with it. Can you share piece of code you are using for this API?
// chall3ng3r //
03-17-2011 06:16 PM
var stream : FileStream = new FileStream();
stream.open( file, FileMode.WRITE );
stream.addEventListener( ProgressEvent.PROGRESS, fileSaveProgressEvent );
stream.addEventListener( Event.COMPLETE, fileSaveComplete );
stream.addEventListener( IOErrorEvent.IO_ERROR, fileSaveError );
stream.addEventListener( Event.CLOSE, fileSaveComplete );
stream.addEventListener(OutputProgressEvent.OUTPUT _PROGRESS, fileSaveProgressEvent );
var png : PNGEncoder = new PNGEncoder();
var bytes : ByteArray = png.encode( value.image );
stream.writeBytes( bytes );
stream.close();However none of the events are fired.
Any help would be greatly appreciated.
BTW: I have tried on the 9.4 sim and on the desktop both have the same issues.
03-17-2011 06:18 PM - edited 03-17-2011 06:19 PM
hey,
i've run into the same problem before. basically the .writeBytes doesnt give off any events. its not an async method. only async methods throw off events such as the ones you are listening for. read the following page and it'll shed some light:
so no bug, just a crappy method haha
EDIT: Just a correction, it does throw one event and its the IOErrorEvent:
ioError:IOErrorEvent — You cannot write to the file (for example, because the file is missing). This event is dispatched only for files that have been opened for asynchronous operations (by using the openAsync() method).
03-17-2011 06:37 PM
Thanks I should have read the docs a bit better
03-17-2011 06:38 PM
ah dont get down on yourself! not your fault - some of the methods of AIR are not as intuitive as others. The read methods are async and the write methods not so much. id rather have it the other way around. maybe some day ![]()
03-17-2011 06:38 PM
Hi,
As you can see from the link J. Rab posted, that FileStream only have one Event, that is ioErrorEvent. Also, since writing to local filesystem is pretty fast, you don't need to subscribe to other events. If you really want to show activity indication, you can make a new instance of ActivityIndicator and position it somewhere on your UI, and hide it at end of function.
But be sure you do that before entering the function which have the code you posted. Otherwise, you won't even see the ActivityIndicator.
for example:
function onButtonPress()
{
showActivity();
saveData();
}
function showActivity()
{
// show processing info
mcActivity.setPosition(275, 24);
mcActivity.visible = true;
mcActivity.animate(true);
}
function saveData()
{
var stream : FileStream = new FileStream();
stream.open( file, FileMode.WRITE );
stream.addEventListener( IOErrorEvent.IO_ERROR, fileSaveError );
var png : PNGEncoder = new PNGEncoder();
var bytes : ByteArray = png.encode( value.image );
stream.writeBytes( bytes );
stream.close();
mcActivity.animate(false);
mcActivity.visible = false;
}
Best,
// chall3ng3r //