0

Ahoy. When i want update information with ENTER_FRAME like this:

import flash.events.Event;

var ticks:uint = 0;
var last:uint = getTimer();
var food:uint = 10;
var wood:uint = 10;
var stone:uint = 10;

stage.addEventListener(Event.ENTER_FRAME, update); // getFPS
stage.addEventListener(Event.ENTER_FRAME, list); //get Materials Info

function update(e:Event){
ticks++;
var now:uint = getTimer();
var delta:uint = now - last;
   if (delta >= 1000) {
            var fps:int = ticks / delta * 1000;
            fpsText.text = String(fps+"fps");
            ticks = 0;
            last = now;
        }

}// 

function list(e:Event){

foodText.text = String(food+"food");
woodText.text = String(wood+"wood");
stoneText.text = String(stone+"stone");

}//

fps drop down.

When i change code like this:

import flash.events.Event;

var ticks:uint = 0;
var last:uint = getTimer();
var food:uint = 10;
var wood:uint = 10;
var stone:uint = 10;

stage.addEventListener(Event.ENTER_FRAME, update); // getFPS

function update(e:Event){
ticks++;
var now:uint = getTimer();
var delta:uint = now - last;
   if (delta >= 1000) {
            var fps:int = ticks / delta * 1000;
            fpsText.text = String(fps+"fps");
            list();
            ticks = 0;
            last = now;
        }

}// 

function list(){

foodText.text = String(food+"food");
woodText.text = String(wood+"wood");
stoneText.text = String(stone+"stone");

}//

fps drop down after 15 minutes.

I know problem is in function list(), but how I list materials quick without slowing fps. How i change this for clean run? Thx for hlp.

ATJ
  • 3
  • 1

1 Answers1

0

I'm assuming there is more code somewhere else that will change the values of food, wood, and stone. No need to update the values on enterframe if they aren't changing. Perhaps you could update the UI only when you change the values? So remove list() from the enter frame and do something like this when you change the values?

function getWood(){
   wood++;
   list();
}

function useWood(){
   wood--;
   list();
}
Andrew Sellenrick
  • 996
  • 1
  • 6
  • 8