[F8] Coding Techniques - Nest Frame loader?
n. Frame Loader - To spread the work of a Flash application across several frames, instead of forcing the application to complete all the work in a single frame. Prerequisites - No For, For...in, or While loops!
Hey all. I've noticed in the map editor I've made: mapEdit, that if you have to load a couple of maps, the system bogs right down to about 3fps. I've pinpointed this on what's returned from the website; Several 10000-character strings, which are parsed with a while loop and transformed into a usable map array. Unfortunately, I'm already doing a frame loader and waiting for the end of the php script to finish returning all the map data. However, the only way I see to sidestep the insane amount of overhead, is to parse the data via frame loader, instead of a while loop. I am not at home right now, so I am unable to test this, but I think this is a possible solution. Extra help is greatly appreciated.
Code:
// dynamic function
onEnterFrame = function() {
Primary();
}
// first test
function frameLoad() {
if (curX1 < maxX1) {
if(curY1 < maxY1) {
// Our nested frame loader?
if (curX2 < maxX2 and !done) {
if (curY2 < maxY2) {
curY2++;
} else {
curY2 = 0;
curX2++;
}
} else {
done = true;
}
if (done) {
curY1++;
}
} else {
curY1 = 0;
curX1++;
}
} else {
curX1 = curY1 = curX2 = curY2 = 0;
done = false;
Primary = finishUp;
}
}
// Run once everything is completed
function finishUp() {
trace("Finally, we're all done.");
}
// Run at startup to prime frameLoad
function init() {
maxX1 = maxY1 = maxX2 = maxY2 = 50;
curX1 = curY1 = curX2 = curY2 = 0;
done = false;
Primary = frameLoad;
}
// Start
init();