Home » actionscript 2.0, actionscript 3.0

Calculating fileSize / converting loaded bytes

21 October 2008 No Comment

The function calculates values from Bytes to KB or MB.
Here we are first checking the value of bytes and if its less that zero or not a number returns null.

Otherwise we are calculating,
1024 Bytes = 1 KB.
1024 KB = 1 MB

/**
* Calculates the File size
*
* @param bytes Loaded bytes or file size in bytes
* @return converted bytes to String.
*/
function fileSize( bytes : Number ) : String
{
if(bytes<0 number =” Number(bytes/1024);” string =” Math.round(fileSize)”>0?(fileSize>1024?(fileSize/1024).toFixed(2)+”MB”:((fileSize.toFixed(2))+”KB”)):(fileSize*1024)+”Bytes” ;

return FileSize_str;
}

Download Source file

VN:F [1.7.7_1013]
Rating: 0.0/10 (0 votes cast)
VN:F [1.7.7_1013]
Rating: 0 (from 0 votes)

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.