Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Adobe AIR Development

Reply
New Developer
Omnipitence
Posts: 22
Registered: ‎01-21-2011
My Carrier: None
Accepted Solution

FileStream Events not fired

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

Playbook Apps

Liquid-Photo
Follow us on Twitter @LiquidPhotoApp
P.S. Did you know you can take a screen shot by holding down the up/down volume buttons on the PlayBook! Great for recording errors.
Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010

Re: FileStream Events not fired

which methods of the filestream class are you trying to use?

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
Developer
peter9477
Posts: 5,634
Registered: ‎12-08-2010
My Carrier: none

Re: FileStream Events not fired

Where are you trying to save it, specifically, and what events are you listening for?  Have you tried the error events too?


Peter Hansen -- (PlayBook and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
chall3ng3r
Posts: 140
Registered: ‎12-25-2010
My Carrier: N/A

Re: FileStream Events not fired

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 //

--
- Our PlayBook Apps: IdeaPad | EasyCrop
- Free Icon Maker for BlackBerry PlayBook developers | 1500+ icons created and counting
- A Kudo is appreciated if you like my post :smileyhappy:
- My post soveld the problem? Please click Accept as Solution.
Please use plain text.
New Developer
Omnipitence
Posts: 22
Registered: ‎01-21-2011
My Carrier: None

Re: FileStream Events not fired

 

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.

 

Playbook Apps

Liquid-Photo
Follow us on Twitter @LiquidPhotoApp
P.S. Did you know you can take a screen shot by holding down the up/down volume buttons on the PlayBook! Great for recording errors.
Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010

Re: FileStream Events not fired

[ Edited ]

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:

 

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html#...

 

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). 

 

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
New Developer
Omnipitence
Posts: 22
Registered: ‎01-21-2011
My Carrier: None

Re: FileStream Events not fired

Thanks I should have read the docs a bit better

Playbook Apps

Liquid-Photo
Follow us on Twitter @LiquidPhotoApp
P.S. Did you know you can take a screen shot by holding down the up/down volume buttons on the PlayBook! Great for recording errors.
Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010

Re: FileStream Events not fired

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 :smileyhappy:

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
Developer
chall3ng3r
Posts: 140
Registered: ‎12-25-2010
My Carrier: N/A

Re: FileStream Events not fired

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 //

--
- Our PlayBook Apps: IdeaPad | EasyCrop
- Free Icon Maker for BlackBerry PlayBook developers | 1500+ icons created and counting
- A Kudo is appreciated if you like my post :smileyhappy:
- My post soveld the problem? Please click Accept as Solution.
Please use plain text.