Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

simple preLoader question

New Here ,
Jan 11, 2008 Jan 11, 2008
Hi everyone
I found a good preloader code online and is working fine. RIght now the AS is showing the bytes loaded and I want it to show the simply the a double digit percentage. For example, I want it to say 79% loaded. I have tried dividing, multiplying and everything else. if you could help please let me know.
Here is my Code

import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.text.TextField;
import flash.net.URLRequest;

var myLoader:Loader = new Loader();

var myRequest:URLRequest = new URLRequest("gallery.swf");

myLoader.load(myRequest);

myLoader.contentLoaderInfo.addEventListener(Event.OPEN,showPreloader);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,showProgress);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showLoadResult);

var loadProgress_txt:TextField = new TextField();

function showPreloader(event:Event):void
{
addChild(loadProgress_txt);
}

function showProgress(event:ProgressEvent):void
{
loadProgress_txt.text ="loading " + event.bytesLoaded + "total " + event.bytesTotal;
}

function showLoadResult(event:Event):void
{
removeChild(loadProgress_txt);
myLoader.x = 50
myLoader.y = 100
addChild(myLoader)
}

Thanks in advance
Ryan
TOPICS
ActionScript
172
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jan 11, 2008 Jan 11, 2008
LATEST
you want to divide bytesLoaded into bytesTotal, multiply by 100 and then get the absolute value. like so:
var loadedPercentage:int=Math.floor((event.bytesLoaded/event.bytesTotal)*100);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines