• 【设为首页】
  • 【收藏闪客居】
当前位置:主页>FLASH AS 编程>AS基础篇>AS 3.0>文章内容
  • AS3 提示类
  • 来源:ASFox(nee) 作者:ASFox(nee) 2008-03-04 【

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
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";
  }
 }
}




上一篇:AS3.0中的位图扭曲变形   下一篇:[AS3]提示信息类-ToolTip
  • 用户名:新注册) 密码: 匿名评论
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)


FLASH源文件

Copyright © 2006-2008 flashas.net All Rights Reserved.
网站内容咨询: admin#flashas.net (#为@) 联系QQ:40777822 浙ICP备06033001号
(本网站最佳浏览解析度为1024*768, 建议使用IE 6.0或以上版本浏览器。)