Posted By

adrianparr on 12/09/10


Tagged

performance hidden memory as3 ram stats double-click mrdoob doob fps


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

mitien
wreaper


AS3 Have hidden performance stats which is made visible by double-clicking in the top-left corner of SWF


 / Published in: ActionScript 3
 

URL: http://mrdoob.com/blog/post/582

For this to work you need get Mr.Doob's Stats class and put it in the 'net/hires/debug' package structure. This code basically makes the stats hidden until you double-click in the top-left corner of the stage. The stats are then draggable and can be hidden again by double-clicking the stats panel.

  1. package {
  2.  
  3. import flash.display.Sprite;
  4. import net.hires.debug.Stats;
  5. import flash.events.MouseEvent;
  6.  
  7. public class HiddenStats extends Sprite {
  8.  
  9. private var _stats:Stats;
  10.  
  11. public function HiddenStats() {
  12.  
  13. _stats = new Stats();
  14. _stats.visible = true;
  15. _stats.alpha = 0;
  16. _stats.scaleX = _stats.scaleY = 0.1;
  17. _stats.x = 0;
  18. _stats.y = 0;
  19. _stats.doubleClickEnabled = true;
  20. _stats.useHandCursor = false;
  21. _stats.mouseEnabled = true;
  22. _stats.mouseChildren = false;
  23. _stats.buttonMode = true;
  24. _stats.addEventListener(MouseEvent.DOUBLE_CLICK, onStats_DOUBLE_CLICK);
  25. _stats.addEventListener(MouseEvent.MOUSE_DOWN, onStats_MOUSE_DOWN);
  26. _stats.addEventListener(MouseEvent.MOUSE_UP, onStats_MOUSE_UP);
  27. addChild(_stats);
  28. }
  29.  
  30. private function onStats_DOUBLE_CLICK(event:MouseEvent):void
  31. {
  32. if (_stats.alpha < 1) {
  33. _stats.alpha = 1;
  34. _stats.scaleX = _stats.scaleY = 1;
  35. _stats.useHandCursor = true;
  36. } else {
  37. _stats.alpha = 0;
  38. _stats.scaleX = _stats.scaleY = 0.1;
  39. _stats.x = _stats.y = 0;
  40. _stats.useHandCursor = false;
  41. }
  42. }
  43.  
  44. private function onStats_MOUSE_DOWN(event:MouseEvent):void
  45. {
  46. _stats.startDrag(false);
  47. }
  48.  
  49. private function onStats_MOUSE_UP(event:MouseEvent):void
  50. {
  51. _stats.stopDrag();
  52. }
  53.  
  54. }
  55.  
  56. }

Report this snippet  

You need to login to post a comment.