(flash cs3/as2)
here what i have so far:
loaded_bytes = Math.round(_root.getBytesLoaded());
total_bytes = Math.round(_root.getBytesTotal());
loadpercent = (loaded_bytes/total_bytes)*100;
//function to randomize the order of myArray
function randmonArray() {
r = function () {
return random(2)*2-1;
};
myArray.sort®;
}
//myArray with 100 square names that is randomized
var myArray:Array = [“s1”, “s2”, “s3”, “s4”, “s5”, …“s100”];
randmonArray();
if (loaded_bytes < total_bytes) {
for (loadpercent; loadpercent < myArray.length {
var removedSquare = myArray.splice(0,1);
unloadMovie(removedSquare);
trace(Math.round(loadpercent) +"removed square is: " +removedSquare);
}
}
else {
gotoAndPlay(“start”);
}
first question: How do i generate at array with 100 items “s1”, “s2”, etc rather than typing every item out by hand!
last question: I want the for loop to splice and unload once every time the loadpercent increases: so rather than have a bar increase in size every 1% that is loaded, i want one item to be spliced from the array and that is used to unload one movie every 1%.
i imagine that i will also need a way to find out how much is loaded instantly and unload clips at the start acoringly: splice and unload at the start so the items in the array match the loadpercent?
Im really close and its these last little things that I need some help on. I’d really appreciate an expert hand so i can get this thing ticking over.
Thanks
Chris
// create array
var myArray:Array = new Array();
for (var i = 0; i <= 100; i++) {
myArray[i - 1] = "s" + i;
}
trace(myArray);
I don’t see any point in splicing the array. Just loop through your array and place the movieclips onto the stage like so:
// create loading bar
for (var i = 0; i < 100; i++) {
duplicateMovieClip(s, "s" + (i + 1), this.getNextHighestDepth()); // assumes an MC on stage called "s"
this["s"+(i+1)]._x = 10 + (i * 5); // assumes "s" is 3 pxs wide and spaces each duplicate 5 px apart
}
Then you could use an onEnterFrame to remove each duplicate as the loadpercent increases
this.onEnterFrame = function() {
removeMovieClip("s" + Math.round(loadpercent));
if (Math.round(loadpercent) == 100) {
gotoAndPlay("start");
}
};

the first array works fantasticly, never again will i have to type pointlessly again!
The second bit works fine, i can prob work out how to get the code to arrange the clips how i want them, (in lines of 10 to create a 10X10 grid)
the last bit of code doesnt remove the clips. i think it removes one but doesnt seem to check to see if the value of loadpercent has changed?..im not sure.
I scribbled it all down off the top of my head…obviously you’ll also need to include the code that updates the value of loadpercent within the onEnterFrame handler.
…the last bit of code doesn’t seem to be picking up every change in loadpercent, so it starts at 24 (because 24% is loaded instantly) 24 then comes up twice, so it seems to try and remove that clip twice. the next number traced is 31 and so on. so rather than all the clips being removed when loadpercent is at 100, loads are left behind.
Any ideas?
this.onEnterFrame = function() {
loaded_bytes = Math.round(_root.getBytesLoaded());
total_bytes = Math.round(_root.getBytesTotal());
loadpercent = (loaded_bytes/total_bytes)*100;
unloadMovie(“s” + Math.round(loadpercent));
trace(Math.round(loadpercent));
if (Math.round(loadpercent) == 100) {
gotoAndPlay(“start”);
}
};
this traces:
24,28,31,34,36,39,42,46,49,52,56,60,64,67,71,76,80,84,89,92,97,100
…the reason for using an array splice was to get random clip names rather than getting them in order as it is doing now
www.onemorechris.co.uk/pt3.fla
(deleted everything else in file but still to big to upload, its saved at the above link)
Should’ve said…it needs to be F8 for me to take a look…sorry.
I’ll take a look, although I can forsee a few problems that you might encounter because of the usual Flash preloading constraints. You’ve identified those problems in your first post. The biggest issue is making sure that your squares are loaded before the rest of the items in the fla, so that they can be positioned on the stage.
Creating the grid is quite straightforward though:
// create grid
initX = 0;
initY = 0;
counter = 0;
for (var i = 1; i <= 10; i++) {
for (var j = 1; j <= 10; j++) {
counter++;
duplicateMovieClip(s, "square" + counter, counter); // assumes an instance of your square on the stage called "s"
gridSquare = this["square" + counter];
trace (gridSquare)
gridSquare._x = initX;
gridSquare._y = initY;
initX += 30;
}
initY += 30;
initX = 0;
}
thank you for your efforts, they are very much welcomed. ill keep going, im sure ill get there
thanks again