Do not use a collection of flash.filesystem.File objects as a dataprovider

I’m sure someone will fill in the technical details in the comments (hint hint, AIR experts), but here’s what I ran into.

I’m building an image upload system, and I’m allowing people to drag & drop images onto the app for upload. When they drop the images, I put all the File objects into an ArrayCollection, and then I rendered previews in a giant TileList driven off that ArrayCollection. Now, I figured that might be a little intensive, but it was taking 5-10 seconds to scroll down one row. I figured that it was just beyond AIR’s capabilities to render these jpg files (they are 2-10MB each) that fast, even off the local file system. So, I switched my TileList to a List, but had the same problem, even though I was just displaying File.name.

When I had that result, I figured there must be something about the flash.filesystem.File object that was causing the problem. So, I created a shadow ArrayCollection that I filled with a custom object, FileLight:

1
2
3
4
5
6
7
8
9
10
11
12
package org.iotashan.file {
    public class FileLight {
        public var name:String;
        public var extension:String;
        public var nativePath:String;
    }
    public function FileLight(name:String,extension:String,nativePath:String) {
        this.name = name;
        this.extension = extension;
        this.nativePath = nativePath;
    }
}

When I drove the TileList off of the ArrayCollection filled with FileLight objects, performance came back to acceptable levels. Feel free to use that code however you want.

Comments