||moock-updates|| blog and preloading petition

colin@moock.org colin@moock.org
Mon Apr 21 10:26:00 2003


[also posted to flashcoders (chattyfig.figleaf.com)]

to all who have felt the pain of building preloaders, please sign the
petition at:
http://www.moock.org/blog/archives/000010.html

(the form to sign is at the very bottom of the page...please only sign if
you strongly agree with the petition)

btw, the petition is part of my new blog :)
http://www.moock.org/blog/

colin


===========================
the preloading petition
===========================

Petition To Macromedia: Better Preloading API

anyone who has tried to create a generic preloader for .swf files or .jpgs
will almost certainly have horror stories to tell. if you do have such a
story, please tell it here. this log entry's comments will constitute an
official petition to macromedia to improve the state of content preloading
in flash. i propose that a new api be created to make preloading generic and
easy to use (see below). anecdotal evidence is good, real code examples are
even better. please post your experiences.

here are just a few of the problems i have encountered:

1) when loadMovie() appears in a script, it doesn't execute until the end of
the frame. this means preloading code must either wait a frame before it
starts or try to detect whether the loadMovie() call has actually executed.
neither workarounds are pretty.

2) there's no support for http server responses such as 404 (not found) or
403 (forbidden).

3) empty movie clips created at authortime have a byte size of 4. empty
clips created with createEmptyMovieClip() have a byte size of 0. empty
levels are undefined, and have a getBytesLoaded() return of undefined. hence
most preloaders have to guess at a magic number when checking for loaded
content...usually something like (loaded > 4 && loaded == total). this is
arcane knowledge that an average developer shouldn't be required to know
just to do something as fundamental as preload some content.

4) _framesloaded, _totalframes, getBytesLoaded(), getBytesTotal(),
onLoad()....which to use??? the current system seems confusing and random to
new flash programmers. only experts know how to preload content properly.

5) the MovieClip.onLoad() handler is wiped out by a loadMovie() call. hence,
there's no object-oriented way to handle movie loading. there's not even a
callback to respond to movie loading.

6) getBytesLoaded()/getBytesTotal() return the uncompressed size of the
movie, which is not actually what's downloading (the movie might be
compressed). download indicators that display bytes or kilobytes are often
inaccurate because they show uncompressed sizes.

7) internet explorer and netscape have different getBytesLoaded() return
values, as follows:
after loadMovie() appears in a script, getBytesLoaded() in the Standalone
Player and Netscape returns:
-first 0
-then the real bytes loaded or
-eventually -1 if the file is not found.
but in Internet Explorer, getBytesLoaded() returns:
-first 0
-then -1
-then the real bytes loaded or
-eventually -1 if the file is not found

i'd like the flash community to stop wasting so much time on preloading.
it's an important part of every single project, yet it's one of the least
refined aspects of actionscript. for a sense of the backflips required to
create a generic preloader, see my copiously commented "image loader w/ pan
and zoom" at the code depot.

here's just a quick idea for a preloading API. i'm not trying to dictate
what the final API should actually be...i'm just trying to show that there's
a better way.
MovieClipLoader.onLoadStart()
MovieClipLoader.onLoadComplete()
MovieClipLoader.onLoadProgress (bytesLoaded,
   bytesTotal,
   kbLoaded,
   kbTotal,
   percentLoaded)
MovieClipLoader.loadClip(target, url)
MovieClipLoader.addListener()
MovieClipLoader.removeListener()

macromedia, please relieve developers everywhere of having to hack together
their own loading systems that very often only partly work. thanks!!

colin moock (and the undersigned...)