can't u just check the name of the photo, id of the photo 

----- Original Message ----
From: ronnlixx <[EMAIL PROTECTED]>
To: [email protected]
Sent: Tuesday, January 29, 2008 8:56:03 AM
Subject: [flexcoders] AS3: How to avoid loading the same asset repeatedly

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.getInsta nce().frame) ;
}

public class PhotoFrame extends Sprite
{
private static var instance:PhotoFrame = null;
private var _loader:Loader = null;

public function PhotoFrame() {
_loader = new Loader();
_loader.contentLoad erInfo.addEventL istener(Event. COMPLETE,
onFrameLoaded) ;

_loader.contentLoad erInfo.addEventL istener(IOErrorE vent.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) ;
//...
}

}





      
____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

Reply via email to