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.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 48
Registered: ‎10-06-2009
My Device: Not Specified

Problem with images and ItemRenderer

I have a list that when selected, displays another list. The second list has custom renderer that downloads thumbmails from a remote server and caches on the device. When selecting various items in the first list to update the second list, the images do not refresh/ load, but the titles do. This happens after the first selection, even if the images are already cached. Does anyone have any ideas? Also, I would like to avoid the image flicker when scrolling through the lists, but have not found any good examples in mxml. Thanks in advance for the help.
Highlighted
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Problem with images and ItemRenderer

hm are you sure the caching is working properly? and do the images load after some time? it might be an issue when it comes to loading the image vs loading the new cell. there is probably a delay caused by the loading. how are you caching the images? a sample of your code would help. good luck!

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
Developer
Posts: 48
Registered: ‎10-06-2009
My Device: Not Specified

Re: Problem with images and ItemRenderer

Here is the code I am using for caching:

 

var imgFile:File = File.applicationStorageDirectory.resolvePath("thumb/topic_" + dataProxy.video + ".jpg");                
                if (imgFile.exists) {
                    thumb.source = imgFile.url;
                    thumb.validateNow();                        
                } else {
                    var urlStream:URLStream = new URLStream();                    
                    var fileStream:FileStream = new FileStream();    
                    
                    var writeFile:Function = function():Boolean {
                        if (urlStream.bytesAvailable > 51200) {
                            var dataBuffer:ByteArray = new ByteArray();
                            urlStream.readBytes(dataBuffer, 0, urlStream.bytesAvailable);
                            fileStream.openAsync(imgFile, FileMode.WRITE);
                            fileStream.writeBytes(dataBuffer, 0, dataBuffer.length);
                            fileStream.close();                                
                        }
                        return true;
                    }
                    
                    var finishWriteFile:Function = function():Boolean {
                        if(urlStream.bytesAvailable > 0) {
                            var dataBuffer:ByteArray = new ByteArray();
                            urlStream.readBytes(dataBuffer, 0, urlStream.bytesAvailable);
                            fileStream.openAsync(imgFile, FileMode.WRITE);
                            fileStream.writeBytes(dataBuffer, 0, dataBuffer.length);                            
                            fileStream.close();                            
                            urlStream.close();
                            
                            thumb.source = imgFile.url;
                            thumb.validateNow();
                        }
                                                
                        //fileStream.close();                            
                        //urlStream.close();
                        
                        //thumb.source = imgFile.url;
                        //thumb.validateNow();
                        
                        return true;
                    }
                          
                    
                    urlStream.addEventListener(Event.COMPLETE, finishWriteFile);
                    urlStream.load(new URLRequest(dataProxy.thumb));

                }               

Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Problem with images and ItemRenderer

[ Edited ]

i havent yet gone through all the source, but one thing that people run into is make sure that the directory "thumb" is actually there and created. if its not there, the image is never saved. so what u should do is after your run the code, double check if hte image actually was saved or not. good luck!

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
New Developer
Posts: 199
Registered: ‎12-29-2010
My Device: Not Specified

Re: Problem with images and ItemRenderer

Try removing the anonymous functions and make them instance functions.

 

I've found when using anon funcs in ECMAScript, it takes values at that INSTANT, meaning that your dataBuffer is probably null.

 

Have you stepped through the code during a debug to ensure it's writing properly?

Developer
Posts: 48
Registered: ‎10-06-2009
My Device: Not Specified

Re: Problem with images and ItemRenderer

Checking to see if the file exists after it is saved sometimes comes up true and sometimes false.

 

I can confirm that the images are caching because on subsequent tries, the files are found and loaded from the cache instead of downloading remotely.

 

Here is what is happening:

 

Fresh "install" with no images cached, item 1 selected. No images are found to be cached so they are downloaded.

 

Item 2 is selected, the list item count changes, the titles change, but the images do not.

 

Restart.

 

Item 1 selected, images are found and loaded from cache.

 

Item 2 is selected, the list item count changes, the titles change, but the images do not.

 

What I can tell you is that when the second item is selected, its as if the image rendering is not done because i am not getting any of the messages that the image is cached or that it will download.

 

So, apparently this is not a writing issue, but a list display issue.

 

I hope that makes sense.

New Developer
Posts: 199
Registered: ‎12-29-2010
My Device: Not Specified

Re: Problem with images and ItemRenderer

Is this Flex or QNX?

Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Problem with images and ItemRenderer

@killerspaz: looks like flex

 

@gerard: what does your list look like? i think the initial render is done properly, but any subsequent renders arent being rendered the right way.

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
Developer
Posts: 48
Registered: ‎10-06-2009
My Device: Not Specified

Re: Problem with images and ItemRenderer

I am using Flex.

 

Some additional information:

 

If the first selection is less than the second, then only the additional items download images. In order words, if the first list contains 6 items and the second list contains 10 items, then only the last for attempt to download images.

 

Should I be doing this in the creation_complete or do you recommend at another time?

 

FYI: When an item is selected, the dataprovided of the second list is being reset. Is there another way to remove items from a list? If I can destroy the list and create a new one, I think it will work.

Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Problem with images and ItemRenderer

in the qnx dataprovider there is a method myList.dataProvider.removeAll() that gets rid of all the items. see if such a method exists for yours.

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