I believe most people just go ahead and load again because the file
should be in the browser cache once it has been loaded.

I would also be interested in the performance effects of each method.

Steve

On 1/29/08, ronnlixx <[EMAIL PROTECTED]> wrote:
> Say i have 400 objects that contain the same loaded png, whats the
> suggested way to avoid loading the same asset repeatedly?
>
> Here's what I did, don't know if it's nuts though.
> To avoid loading the same png every time I made a singleton of the
> PhotoFrame class and return a copy of the origional png as a bitmap.
> It works, don't know the performace difference between using a new
> Loader vs creating cloned bitmaps each iteration.
> What is the suggested way to avoid loading the same asset multiple
> times?
>
>
> for (var i:int=0; i < 400; i++){
>     new Photo(photoXML, PhotoFrame.getInstance().frame);
> }
>
> public class PhotoFrame extends Sprite
> {
>     private static var instance:PhotoFrame = null;
>     private var _loader:Loader = null;
>
>     public function PhotoFrame(){
>         _loader = new Loader();
>         _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
> onFrameLoaded);
>
> _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,
> onLoadError);
>         _loader.load( new URLRequest("frame.png") );
>     }
>
>     public static function getInstance():PhotoFrame{
>         if(instance == null) instance = new PhotoFrame();
>         return instance as PhotoFrame;
>     }
>
>     public function get frame():Bitmap{
>         var image:Bitmap = Bitmap(_loader.content);
>         return new Bitmap(image.bitmapData.clone());
>     }
>
>     private function onLoadError(e:IOErrorEvent):void{
>         trace(e.text);
>     }
>
>     private function onFrameLoaded(e:Event):void{
>         trace('loaded');
>     }
> }
>
>
> public class Photo extends EventDispatcher
> {
>     private var _frame:PhotoFrame;
>
>     public function Photo(photoXML:XML, frame:PhotoFrame){
>         _frame = frame;
>         addChild(_frame);
>         //...
>     }
>
> }
>
>
>
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
> Yahoo! Groups Links
>
>
>
>

Reply via email to