我正在运行我将要用于基于文本的冒险的程序,它似乎工作得非常好,但我注意到我的程序严重减速。我一直在使用trace(System.totalMemory);发现问题并且内存非常线性增加,每帧大约500b-1kb。
{
addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
function fl_EnterFrameHandler(event: Event): void {
//this block sets up the blinking cursor
var_x = var_x + 1;
if (var_x > 18) {
var_x = 0;
if (str_cursor == " ") {
str_cursor = "█";
} else {
str_cursor = " ";
}
}
//Checking to see if a picture needs to be drawn or not
if (picture != "") {
fulltext = (picture + "\n\n" + responce + "\n\n" + ">>>" + user_input + str_cursor);
} else {
fulltext = (responce + "\n\n" + ">>>" + user_input + str_cursor);
}
//Setting the interval of the draw string
uInt = setInterval(writeIt, 1);
function writeIt() {
if (!printed) {
//Finding the substring of the draw string and assignign to the text field
fl_TF.text = fulltext.substring(0, count);
count += count_speed;
if (count > fulltext.length) {
clearInterval(uInt);
//Stoping the print loop
printed = true;
count = 0;
}
} else {
user_input = inputField.text;
fl_TextToDisplay = fulltext;
fl_TF.text = fl_TextToDisplay;
}
}
if (printed) {
user_input = inputField.text;
fl_TextToDisplay = fulltext;
fl_TF.text = fl_TextToDisplay;
clearInterval(uInt);
}
}
我似乎无法找到泄漏,因为我已经在不同的点跟踪了所有涉及控制台的变量。
您可以在此处找到该计划的屏幕截图:http://i.imgur.com/dSWLeD5.gif
答案 0 :(得分:1)
哪个范围有哪些?
通常:
setInterval
。有
Timer
- 班级。你想用这个古玩代码做什么?