-
1. Re: BitmapData Loader
kglad Oct 4, 2013 1:09 PM (in response to Ron Colmen)i'm exporting 1280x800 images on a project i just finished and it takes less than 5 seconds? how long is it taking you and for what size images?
-
2. Re: BitmapData Loader
Ron Colmen Oct 4, 2013 7:12 PM (in response to kglad)900 x 600. For most users it takes under 10 seconds.
My issue is, if there's a break in the users internet connection the bitmap exporting process never ends and the user will never know about it. That's the reason for adding the loader.
-
3. Re: BitmapData Loader
kglad Oct 4, 2013 7:34 PM (in response to Ron Colmen)the exporting is done with a for-loop that can't be interrupted. if it takes 10 seconds, your flash should freeze for 10 seconds. does it?
-
-
5. Re: BitmapData Loader
kglad Oct 5, 2013 8:09 AM (in response to Ron Colmen)then all you can do is to "chunk" the for-loop and provide periodic updates. this is from http://www.amazon.com/gp/product/1435460200/ref=s9_simh_co_p14_d5_i1?pf_rd_m=ATVPDKIKX0DER &pf_rd_s=left-1&pf_rd_r=0BTBFZ0YDPP0ZHKXKTP4&pf_rd_t=3201&pf_rd_p=1280661682&pf_rd_i=typ01
do-loops, for-loops and while-loops
Loop types that execute from start to end before anything updates on stage include do-loops, for-loops and while loops. They cannot be used to animate objects because no matter what code you use to execute the loop and no matter what you do to (try and) slow it down, it will still execute from start to finish before anything changes on stage. They are appropriately used for rapid execution of code.
There is never a situation when you should intentionally slow these loops. However, there are situations when you might want to break these loops into more than one chunk so the stage can update between each chunk.
Chunks
For example, if you have a for-loop that takes 10 seconds to execute, your game will appear to freeze for 10 seconds after this loop starts. Nothing will update on stage and nothing will respond to user input. Either you should warn your user before starting that loop or you should break that loop into several smaller chunks that allow visual updates to the user so they do not think your game is broken.
For example, this for-loop that adds odd numbers (and shows the first m odd numbers sum to m*m) freezes my Flash Player for about 9 seconds.
var i:Number;
var n:Number=3000000000;
var s:Number=0;
var startI:Number=1;
var endI:Number=n
var startTime:int=getTimer();
for (i=startI; i<endI; i+=2) {
s+=i;
}
// 9 seconds
trace((getTimer()-startTime)/1000,s,n*n/4,s-n*n/4);
The following technique shows how to break this (and any other for-loop) into chunks that allow the Flash Player to update every second.
var i:Number;
var n:Number=3000000000;
var s:Number=0;
var startTime:int=getTimer();
// This is the number chunks into which the previous for-loop will broken. If the // previous for-loop took about 9 seconds, using 10 chunks means there will be updates // about every 0.9 seconds.
var chunks:int=10;
var startI:Number=1;
var endI:Number=n/chunks;
var t:Timer=new Timer(100,1);
- t.addEventListener(TimerEvent.TIMER,f);
f();
function f(e:Event=null):void {
for (i=startI; i<endI; i+=2) {
s+=i;
}
trace("stage update",startI,endI,s);
if (endI<n) {
t.reset();
t.start();
} else {
trace((getTimer()-startTime)/1000,s,n*n/4,s-n*n/4);
}
startI+=n/chunks;
endI+=n/chunks;
}
-
6. Re: BitmapData Loader
Ron Colmen Oct 5, 2013 9:19 AM (in response to kglad)Thanks for sharing! (as3?)
I'll give it a try.
-
7. Re: BitmapData Loader
kglad Oct 5, 2013 9:46 AM (in response to Ron Colmen)yes, that's as3.
here it is in as2:
var i:Number;
var n:Number=3000000000;
var s:Number=0;
var startTime:Number=getTimer();
// This is the number chunks into which the previous for-loop will broken. If the // previous for-loop took about 9 seconds, using 10 chunks means there will be updates // about every 0.9 seconds.
var chunks:int=10;
var startI:Number=1;
var endI:Number=n/chunks;
clearInterval(fI);
var fI:Number = setInterval(f,100);
f();
function f(e:Event=null):void {
for (i=startI; i<endI; i+=2) {
s+=i;
}
trace("stage update",startI,endI,s);
if (endI==n) {
trace((getTimer()-startTime)/1000+" "+s+" "+n*n/4+" "+s-n*n/4);
clearInterval(fI);
} else {
startI+=n/chunks;
endI+=n/chunks;
}
}
-
8. Re: BitmapData Loader
Ron Colmen Oct 5, 2013 10:06 AM (in response to kglad)Thanks once again.
The bold line is not recoganized in as2.
var i:Number;
var n:Number=3000000000;
var s:Number=0;
var startTime:Number=getTimer();
// This is the number chunks Numbero which the previous for-loop will broken. If the // previous for-loop took about 9 seconds, using 10 chunks means there will be updates // about every 0.9 seconds.
var chunks:Number=10;
var startI:Number=1;
var endI:Number=n/chunks;
clearInterval(fI);
var fI:Number = setInterval(f,100);
f();
function f(e:Event=null):Void { //this line requested argument to null doesn't work in as2?
for (i=startI; i<endI; i+=2) {
s+=i;
}
trace("stage update"+" "+startI+" "+endI+" "+s);
if (endI==n) {
trace((getTimer()-startTime)/1000+" "+s+" "+n*n/4+" "+s-n*n/4);
clearInterval(fI);
} else {
startI+=n/chunks;
endI+=n/chunks;
}
}
-
9. Re: BitmapData Loader
kglad Oct 5, 2013 10:13 AM (in response to Ron Colmen)use:
function f():Void{
-
10. Re: BitmapData Loader
Ron Colmen Oct 5, 2013 10:56 AM (in response to kglad)When I run this, the flash player gives a warning (A script in this movie is causing flash player to run slowly...). What's wrong?
var i:Number;
var n:Number=3000000000;
var s:Number=0;
var startTime:Number=getTimer();
// This is the number chunks Numbero which the previous for-loop will broken. If the // previous for-loop took about 9 seconds, using 10 chunks means there will be updates // about every 0.9 seconds.
var chunks:Number=10;
var startI:Number=1;
var endI:Number=n/chunks;
clearInterval(fI);
var fI:Number = setInterval(f,100);
f();
function f():Void{
for (i=startI; i<endI; i+=2) {
s+=i;
}
trace("stage update "+startI+" "+endI+" "+s);
if (endI==n) {
trace((getTimer()-startTime)/1000+" "+s+" "+n*n/4+" "+s-n*n/4);
clearInterval(fI);
} else {
startI+=n/chunks;
endI+=n/chunks;
}
}
-
11. Re: BitmapData Loader
kglad Oct 5, 2013 12:26 PM (in response to Ron Colmen)as2 is slow so that's too ambitious for it. use:
var i:Number;
var n:Number=3000;
var s:Number=0;
var startTime:Number=getTimer();
// This is the number chunks Numbero which the previous for-loop will broken. If the // previous for-loop took about 9 seconds, using 10 chunks means there will be updates // about every 0.9 seconds.
var chunks:Number=10;
var startI:Number=1;
var endI:Number=n/chunks;
clearInterval(fI);
var fI:Number = setInterval(f,100);
f();
function f():Void{
for (i=startI; i<endI; i+=2) {
s+=i;
}
trace("stage update "+startI+" "+endI+" "+s);
if (endI==n) {
trace(((getTimer()-startTime)/1000)+" "+s+" "+(n*n/4)+" "+(s-n*n/4));
clearInterval(fI);
} else {
startI+=n/chunks;
endI+=n/chunks;
}
}



