-
getTimer(); for download speed variable
hi...
i have been searching google and yahoo for hours on this one with no success grrr
i have an .fla, which loads goes to different frames in the timeline according to the download speed of the user. i understand how it should work... start timer > upload file > stop timer > calculate download speed - easy?
so what is this simple code im missing to find the download speed? from my fruitless searching, the only relevant code i could find, is this:
Code:
var time1 = getTimer();
targetClip.loadMovie("example.swf");
targetClip.onLoad = function()
{
var time2 = getTimer();
var totalTime = (time2 - time1)/1000;
var fileSize = targetClip.getBytesTotal();
var connectionSpeed = (fileSize/totalTime); // Bytes per second. Multiply by 8 to get bits per second.
}
... but i have test this, which gives an undefined property error grrr.... so what is the actionscript 3, to find the value of the download speed?
please help if you can
thanks
-
Use a Loader to load the example movie. You will also have to import getTimer.
Code:
import flash.utils.getTimer;
var time1:int = getTimer();
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
loader.load(new URLRequest("example.swf"));
function loadComplete(event:Event):void{
var elapsedSeconds:int = (getTimer() - time1)/1000;
var connectionSpeed:Number = LoaderInfo(event.currentTarget).bytesTotal/elapsedSeconds;
//do something with connectionSpeed.
}
-
Flactionscrish
If you aren't using AS2, ignore this
Try looking at this code:
PHP Code:
var time1 = getTimer(); var container:MovieClip = createEmptyMovieClip("container", getNextHighestDepth()); var mcLoader:MovieClipLoader = new MovieClipLoader(); mcLoader.addListener(this); mcLoader.loadClip("example.swf", container);
function onLoadInit(mc:MovieClip) { trace(time1); trace("onLoadInit: " + mc); var time2 = getTimer(); var totalTime = (time2 - time1)/1000; var fileSize = container.getBytesTotal(); var connectionSpeed = (fileSize/totalTime); // Bytes per second. Multiply by 8 to get bits per second. trace(connectionSpeed); }
Does that help?
ktu[k-two]
he who hesitates is lost; so i guess i'll wander intently
Are you sure this is real?
Life is Love, Love is Blind, Blind we go through Life.
Life isn't hard, dealing with your self is.
The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.
-
I believe he only found as2 in his search, but wanted as3.
In addition to the code I posted above, it may be necessary to add a cache-busting parameter to the url to prevent caching the example swf.
-
thank you ever so much for your post... thats fantastic!!!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|