| scaleContent
Fix for the the Macromedia Loader Component
Flash MX 2004 v.7.0 and 7.2
The Problem
As you may have seen I use examples
of MovieClips containing the Macromedia Loader component
for my Bgx Flexible List Component and struggle since quite
a while with the fact that in particular using Internet Explorer
the loaded content is not scaled even though scaleContent
is set to true.
I have now made an effort to track down exactly what happens
and found out that the component starts checking the load
progress by initially setting the variable that stores the
_totalBytes of the file to load
to -1.
When checking load progress it then checks first 3 times
if that property is still -1 (instead of 0) which basically
means loading hasn't started yet.
If after 3 checks the value is still -1 the component aborts
checking for load progress, dispatching the complete
event without actual check if the file has been loaded or
not. In turn that means that scaling will be attempted before
the content is loaded, once it arrives it doesn't get scaled
anymore.
mx.controls.ExternalContent.asif (x.failedOnce >
3)checkLoadProgress()
As I noticed it may take more than 3 loops before the actual
load starts when you request many loads simultaneously like
with the Flexible List examples or if you simply have a bad
connection over the internet.
Solution
There are several ways of tackling the problem, however the
most manageable seems to me to override the checkLoadProgress()function of the Loader component. This way everything
stays intact as it is, you don't manually change pre-installed
core classes (which may have unpredictable side results) and
can still use the commodity of the component as-is.
The code below is a variation of the original component code
found in mx.controls.ExternalContent.as,
changing the hardcoded number of tries (3) to a variable maxTries
that you can set at will.
To use it either paste the code anywhere into your Flash
file (e.g. at the first frame of the main timeline) before
the Loader is actually used or download
the BgxLoaderFix.as file ( ,
2 kB) and include it using
#include "BgxLoaderFix.as"
maxTries = 560;
Clarification
As I got more than one inquiry about this here some clarifications:
Including the script once will override all Loader instances
for your whole project. That includes Loader instances on
any other internal timeline or even SWFs that are loaded externally.
If you want to test if it works try adding trace(maxTries
+ " " + this); in
the .as file just at the top of the checkProgess function.
This should output the maxTries
value defined wherever you included the script plus the instance
path of the current Loader.
Variations
The syntax above is the one I thought gives you the least
hassle, letting you define the override at startup, this being
valid for your entire project and you can still use the MM
component as is or simply fix existing projects by adding
two lines of code.
However there are other options:
- If you want you could define maxTries as a property of
the Loader so you can adjust it for each instance, if wanted.
To do so change var maxTries:Number =
500; into Loader.prototype.maxTries:Number
= 500;
Note that you also have to change if
(x.failedOnce > maxTries) into if
(x.failedOnce > this.maxTries);
- If you dare you can also remove the bit that dispatches
the complete event alltogether, as Jeff Tapper has done
in his version (see http://jeff.mxdj.com/read/1018476.htm)
- You can create a new component subclassing the existing
one, that's again the way Jeff Tapper has chosen (see http://jeff.mxdj.com/read/1018476.htm)
|