How do upload progress
Copy link to clipboard
Copied
How to upload a ByteArray and show progress?
Note: not the progress of the response from the server but sending the ByteArray.
Note: Adobe Flash CS5 (my project is "web")
I'm converting a MovieClip with jpegencoder (bytearray) to sent to a server with "URLLoader", the problem is that the progress of the URLLoader is just the response from the server and not sending.
How to make a progress of "send"?
Copy link to clipboard
Copied
this is an excerpt from Flash Game Development: In a Social, Mobile and 3D World
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.
Copy link to clipboard
Copied
What's this? Spam?
Copy link to clipboard
Copied
no, it's an explanation of how to display upload progress for a loop that cannot normally be interrupted.
Copy link to clipboard
Copied
So basically, what you mean is:
- Should I use the new "socket" to "http" ("multipart" or "input")
- use "Socket.writeByte" to send chunks of "ByteArray" each "setTimeout"
- And simulate the calculation of progress has already been sent to "Socket.writeByte"
Is it?
Thanks for your attention!
Copy link to clipboard
Copied
are you looping through your bytearray in a for-loop?
Copy link to clipboard
Copied
Thanks again for your interest.
Then I used "for-loop" with Socket.writeByte(myByteArray)
but as AS3 does not support "thread" so I used "setTimeout" this is right?
Copy link to clipboard
Copied
no, you use chunks as mentioned above.
here's an example from the above referenced book. 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;
}
Copy link to clipboard
Copied
Thank you for example, I still have to use "new Socket" to send the data, am I right?
Copy link to clipboard
Copied
use whatever you're currently using that works. you're just breaking your for-loop into several chunks so you can display the progress.

