In this script, each time the user press the space bar, a new picture is displayed
(in my real application, the picture is taken from a database. Here for this example a static picture is OK)
If the picture doesn’t exist, a default picture is loaded.
Here is the corresponding code, each time you press the space bar, the “test.png” picture is loaded
If it isn’t present, it loads ““noscreen.png””
I thought that it was working correctly (even if I had a doubt on a potential loop problem in the function, since a new picture load was called when I’was already in the loader)
Anyway, this seemed to work…until I discovered that if the “noscreen.png” was missing too…the CPU began to fly off!
You can do the test by yourself, watching the task manager, press on the space bar continually
- with the “noscreen.png” present…no problems
- with the “noscreen.png” missing, the CPU flies…and never get down!
I suppose that this is because it looks after a “test.png” picture,
then has the instruction to load a “noscreen.png” if it’s missing
…but this last file is missing itself…so it’s looping continually…isn’t it?
So, to summarize
How would you do to load a picture, and subsitute it by another one if missing
…with the fact that this last one could miss from the user PC (oh, yes…it will be a projector app) too
and it that case it must be skipped simply
Many thanks!!
MC_loader = new MovieClipLoader();
preload = new Object();
MC_loader.addListener(preload);
preload.onLoadError = function(targetMC) {
//if problem loading a picture, load a default picture called "noscreen.png"
MC_loader.loadClip("noscreen.png", targetMC);
};
preload.onLoadInit = function(targetMC) {
//
};
//
//
function stageDown() {
if (Key.getCode() == 32) {
MC_loader.loadClip("test.png", "screenshot_mc.screenHolder_mc");
}
}
//
var keyListener:Object = new Object();
keyListener.onKeyDown = stageDown;
Key.addListener(keyListener);