V
V
Vimake2014-01-25 19:02:38
ActionScript
Vimake, 2014-01-25 19:02:38

Why does the preloader not work on AS?

There is a preloader code.

stop();
    var load_info:TextField = new TextField();
  load_info.text =  "Загрузка...";
  load_info.x=318,95;
  load_info.y=476,25;	
  addChild(load_info);
  var tfNameFormat:TextFormat = new TextFormat();
    tfNameFormat.size = 14;
    tfNameFormat.color = 0xffffff;
  load_info.setTextFormat(tfNameFormat);
  
addEventListener(Event.ENTER_FRAME, loadF);

function loadF(e:Event):void{
var TLoad:Number = loaderInfo.bytesTotal;
var loaded:Number = loaderInfo.bytesLoaded;
var total:Number = loaded/TLoad;
if(loaded == TLoad){
removeEventListener(Event.ENTER_FRAME, loadF);

} else {
load_info.text = Math.floor(total*100) + " %";
  addChild(load_info);
}
}

Doesn't work (text is not recorded)
load_info.text = Math.floor(total*100) + " %";
  addChild(load_info);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Flasher, 2014-01-25
@alexvoz

why addChild(load_info); in handler? this code fires every frame
needs to be traced

stop();
var load_info:TextField = new TextField();
load_info.text =  "Загрузка...";
load_info.x=318,95; //зачем дробные части?
load_info.y=476,25; //зачем дробные части?
var tfNameFormat:TextFormat = new TextFormat();
tfNameFormat.size = 14;
tfNameFormat.color = 0xffffff;
load_info.setTextFormat(tfNameFormat);
addChild(load_info);
addEventListener(Event.ENTER_FRAME, loadF);

function loadF(e:Event):void{
    var TLoad:Number = loaderInfo.bytesTotal;
    var loaded:Number = loaderInfo.bytesLoaded;
    var total:Number = loaded/TLoad;
    if (loaded == TLoad) {
        removeEventListener(Event.ENTER_FRAME, loadF);
    } else {
        load_info.text = Math.floor(total*100) + " %";
        trace(load_info.text, (Math.floor(total*100) + " %"))
    }
}

In general, there is very little information. Is this preloader in a separate class or in the timeline? What IDE is being used, etc.

E
EjIlay, 2014-10-15
@EjIlay

If this code is in the preloader itself, which is like a separate class, then it is already loaded and its loaderInfo is already 100% in place.
Also, you need to check if the textField is not static. If it was put in Flash IDE, then it has a drop-down list in its properties in which you need to select dynamic text

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question