Hi All,
Here I am going to give the tips about the Flex AIR application native application functionality. When I was working in a Flex AIR application to display the filesystem and the file's icon like windows explorer interface, I found the difficulties to show the file icon in AIR application. Because AIR application itself has some limitations to access the OS native application functionalities. So I did some my R & D works and after a quite search, I had found a steven's article, which helped me lot to complete this requirement. I have given some technical stuffs ...Please check it below...
File property BitmapData object
AIR has support for retrieving the native system icons in whatever supported sizes exist. The icons are stored as a property of each File object as BitmapData, in an array, File.icon.bitmaps. Each element in the array is the same icon at different sizes, e.g. 32×32, 16×16 etc.
In order to get at an icon at a given size, you can’t rely on what sizes are available at a given element position, so you need to create a new (empty) BitmapData object at your target dimension, then iterate through File.icon.bitmaps until you hit the matching-sized BitmapData object. Once you have a match, you can put the matching data into your own BitmapData object. Here’s a brief example:
Code:
public function get32Icon():BitmapData {
var myFile:File = new File("C:/foo.txt");
var bmpData:BitmapData = new BitmapData(32, 32);
for (var i:uint = 0; i < myFile.icon.bitmaps.length; i++) {
if (myFile.icon.bitmaps[i].height == bmpData.height) {
bmpData = myFile.icon.bitmaps[i];
}
}
return bmpData;
} now We have my icon data, in an object that also contains other information about the file, like its name etc. To display it in a TileList, or other component, I just use a custom ItemRenderer. I set up an image tag for the icon within the renderer:
Code:
<mx:Image width="32" height="32" source="{getIcon(data)}" /> then create a method in the renderer to return the icon data to the image component:
Code:
private function getIcon(data:Object):Bitmap {
var bmpData:BitmapData = new BitmapData(32, 32);
bmpData = data.icon;
var iconBmp:Bitmap = new Bitmap(bmpData);
return iconBmp;
} Now each time the ItemRenderer has to render an item, it gets the relevant icon, the filename etc. and displays them within the TileList ...
Hope this tips can be very useful to you ...
Thanks
Karpagarajan.R