views:

390

answers:

2

Hello,

just a quick question reguarding how to make a preloader animate backwards. So the bar decreases in width as the load number gets larger.

Here's my code

    onClipEvent (enterFrame) {
    loading = _root.getBytesLoaded();
    total = _root.getBytesTotal();
    if (percent == undefined) percent = 0;
    percent -= (percent-((loading/total)*100))*.25;
    per = int(percent);
    percentage = per+"%";
    loadBar._width = per*9.70;
    if (percent>99) {
     _root.gotoAndStop(2);
    }
}

Many thanks,

Matt

+1  A: 

change the line

loadBar._width = per*9.70;

into

loadBar._width = (100 -per)*9.70;

is a quick and dirty way to do it

Hendrik
+1  A: 

I think this is simpler:

onClipEvent (load) {
 onEnterFrame = function () {
  loading = _root.getBytesLoaded();
  total = _root.getBytesTotal();
  percent = Number(loading/total);
  this._xscale = (1-percent)*100;
  trace(percent);
  if (percent>=1) {
   //_root.gotoAndStop(2);
   delete (onEnterFrame);
  }
 };
}

And it will stop after conditon (percent>=1) become true.

Konrad