PDA

View Full Version : FileSystemDataGrid tiny problem.


fx.barrett
04-15-2009, 10:14 AM
Hi guys,

I have a tiny problem here and I was not able to solve it ( yet ). I have a FileSystemDataGrid with 3 columns ( name, modificationDate, size ). The first column ( name ) has a custom itemRenderer so I can replace the default icons with the actual icons from the users OS ( if he's on Vista, it will display Vista icons, if he's on Mac, it will display Mac icons ).

Until now, everything is fine, when I run the app it replaces the icons nicely BUT: if I go a folder down then for some reason it won't render each row. Example: I start with C: D: E: F: and I go 1 level down into C: where I should see the folders on C: ... instead of that, I see 2-3 actual folders that I have on C: and the other folders are replaced with C: D: E: F: ... the funny thing is that if I embed the file name to a tool tip, then the ToolTip actually shows Program Files instead of C: and Windows instead of E: ... so, this is the problem, for some reason, certain items don't get rendered correctly, the names are not rewritten nor is the icon changed.

Here are 2 images that demonstrate the problem:

-- Working fine when I first open the window.
http://img21.imageshack.us/img21/5387/86006521.jpg

-- When I go one level down into C: it goes crazy:
http://img21.imageshack.us/img21/4223/18820198.jpg

I tried to clear and refresh the fileSystem after directoryChange event but with not results... Is there a way I can force the itemRenderer to render itself again?

Thanks.

EDIT: If I close the explorer and reopen it then the content is rendered ok again... if I go one level down, it's gone wild... Any ideas? Hints?

fx.barrett
04-15-2009, 11:26 AM
Nevermind, I solved the problem by rethinking a bit the whole rendering. I used an inline renderer to render each row and pass the desired data to my component that way. Everything is working fine now.

EDIT: Another solution would be to override the public set data method in the component that you'll be using as a renderer. Clear code this way and everything seems to work fine. Something like this:

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.filesystem.File;

[Embed(source="Assets.swf", symbol="TreeFolderClosed")]
private static var folderIcon:Class;

[Embed(source="Assets.swf", symbol="TreeNodeIcon")]
private static var fileIcon:Class;

override public function set data(value:Object):void
{
super.data = value;

if (value.name) iconLabel.text = value.name as String;
if (value.url) setIconSource(value.url as String);
}

private function setIconSource(value:String):void
{
var bmData:BitmapData;
var cloneBmData:BitmapData;
var file:File = new File(value);
var icons:Array = file.icon.bitmaps;

// 16x16
if(icons.length > 1) bmData = icons[icons.length - 1];
else bmData = icons.bitmaps[0];

// The cloned bitmapdata
cloneBmData = bmData.clone();

// Check if the bitmap is empty
if(cloneBmData.threshold(bmData, new Rectangle(0,0, bmData.width, bmData.height), new Point(), ">", 0) == 0)
{
if(file.isDirectory) iconImage.source = folderIcon;
else iconImage.source = fileIcon;
}
else
{
iconImage.source = new Bitmap(bmData);
}
}