版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://asfox.blogbus.com/logs/16017531.html
package {
//
import flash.display.Sprite;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.ui.Keyboard;
import flash.utils.getTimer;
import flash.system.System;
//
public class documentClass extends Sprite {
//
var active:Boolean = false;
var allLogos:Array = new Array();
var Counter:TextField = new TextField();
var currentTime:int = 0;
var FPS:TextField = new TextField();
var Instructions:TextField = new TextField();
var Memory:TextField = new TextField();
var noOfLogos:int = 100;
//
public function documentClass():void {
stage.addEventListener(KeyboardEvent.KEY_UP, keyListener);
showHUD();
}
//
public function decreaseLogos(thousand:Boolean = false):void {
if (!active) return;
stopTest();
if (thousand) {
if (noOfLogos > 1000) {
noOfLogos = noOfLogos-1000;
}
} else {
if (noOfLogos > 100) {
noOfLogos = noOfLogos-100;
}
}
startTest();
}
//
public function increaseLogos(thousand:Boolean = false):void {
if (!active) return;
stopTest();
if (thousand) {
noOfLogos = noOfLogos+1000;
} else {
noOfLogos = noOfLogos+100;
}
startTest();
}
//
public function keyListener(event:KeyboardEvent):void {
if (event.keyCode == Keyboard.UP) startTest();
if (event.keyCode == Keyboard.DOWN) stopTest();
if (event.keyCode == Keyboard.RIGHT) {
if (event.ctrlKey == true) {
increaseLogos(true);
} else {
increaseLogos();
}
}
if (event.keyCode == Keyboard.LEFT) {
if (event.ctrlKey == true) {
decreaseLogos(true);
} else {
decreaseLogos();
}
}
}
//
public function mainLoop(event:Event):void {
var n:int;
for (n=0;n<noOfLogos;n++) {
var currentLogo:Logo = allLogos[n];
currentLogo.updatePosition();
}
updateHUD();
}
//
public function showHUD():void {
FPS.text = "FPS";
Counter.text = "Objects";
Counter.x = 50;
Memory.text = "mem";
Memory.x = 200;
var instText:String = "<font size='16'><b><u>Instructions</u></b>";
instText += "\nUp - starts the test";
instText += "\nDown - stops the test";
instText += "\nRight - increases the number of logos by 100";
instText += "\nLeft - decreases the number of logos by 100";
instText += "\nCtrl-Right - increases the number of logos by 1000";
instText += "\nCtrl-Left - decreases the number of logos by 1000";
Instructions.htmlText = instText;
Instructions.x = 275;
Instructions.y = 170;
Instructions.autoSize = TextFieldAutoSize.CENTER;
stage.addChild(FPS);
stage.addChild(Counter);
stage.addChild(Memory);
stage.addChild(Instructions);
}
//
public function startTest():void {
if (active) return;
var n:int;
for (n=0;n<noOfLogos;n++) {
var myLogo:Logo = new Logo(stage.stageWidth/2, stage.stageHeight/2);
allLogos[n] = myLogo;
stage.addChild(myLogo);
}
stage.addEventListener(Event.ENTER_FRAME, mainLoop);
active = true;
Instructions.y = -200;
Counter.text = "Objects :"+noOfLogos.toString();
}
//
public function stopTest():void {
if (!active) return;
stage.removeEventListener(Event.ENTER_FRAME, mainLoop);
var n:int;
for (n=0;n<noOfLogos;n++) {
stage.removeChild(allLogos[n]);
var currentLogo:Logo = allLogos[n];
currentLogo = null;
}
active = false;
Instructions.y = 170;
}
//
public function updateHUD():void {
var fps:Number = 1/((getTimer()-currentTime)/1000);
currentTime = getTimer();
FPS.text = "FPS: "+Math.round(fps).toString();
Memory.text = "Mem :"+(Math.round((System.totalMemory/1048576)*10)/10).toString()+" MB";
}
}
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |