0

I am wondering about performance in such a scenario where there could be 100 Bitmap element on stage.

If I constructed those bitmaps using URL, would each bitmap tries to download the image file from the URL regardless the fact that they all use the same image URL?

And, if I use an image to construct those bitmaps, I will have to download the image only once, so, all bitmaps will use the same image? so, when to use the URL?

I would appreciate it if someone clarifies the difference between two approaches in-term of memory and bandwidth utilization, when to use each one?

simo
  • 23,342
  • 38
  • 121
  • 218

1 Answers1

0

The URL is only requested once, no matter how often you create a Bitmap with the same URL, so it won't make a difference from that perspective.

However the difference is, if you use an URL to instanciate a Bitmap the first time, you (very likely) have to wait until the image is loaded, and then update the stage to display it.

Update: I've made a quick jsfiddle: http://bit.ly/10Xavkf if you take a look at the network-tab you can see that the image is only requested once.

olsn
  • 16,644
  • 6
  • 59
  • 65
  • Thanks, so isn't there a difference from memory perspective? – simo May 15 '13 at 08:37
  • No, the memory-perspective should be the least of all issues, because your browser will/should take care of not caching an image with the same URL twice. - However if you create 100 instances of a bitmap, it is the convention and much better code if you preloaded that image. – olsn May 15 '13 at 08:45
  • Thanks for clarification, by the way, I found that using an image is more robust than using URL, specially for IE, sometimes I am forced to use a loaded image instead of URL to make it work, even for chrome .. – simo May 15 '13 at 08:48
  • 1
    Yes, I'd recommend you to use URL only for quick tryouts, not for production-code – olsn May 15 '13 at 08:52