论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash AS编程教程
Tag:2.0,3.0菜鸟,游戏,,cs,技巧,源码,,文本,文字,函数,音乐,随机,拖拽,asp,access,xml,mc,视频教程

AS3 提示类

文章类别:Flash AS编程 | 发表日期:2008-10-6 18:37:09


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

视频教程列表
文章教程搜索
 
Flash AS推荐教程
Flash AS热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058