Posted By

lzyy on 10/22/08


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tspitzr


AS3 彩蛋 键盘事件


 / Published in: ActionScript 3
 

可以通过特定的按键触发彩蛋

  1. //color egg
  2. function colorEgg()
  3. {
  4. stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
  5. stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
  6. stage.addEventListener(Event.DEACTIVATE, clearKeys);
  7. }
  8.  
  9. colorEgg();
  10.  
  11. var keyDowns = '';
  12. function keyPressed(evt)
  13. {
  14. //Tracer.debug(evt.keyCode);
  15. keyDowns += evt.keyCode.toString();
  16. }
  17.  
  18. function keyReleased(evt)
  19. {
  20. if(keyDowns == '76908989')
  21. {
  22. var txt:TextField = new TextField();
  23. txt.htmlText = '<font color="#ff6600" size="20" face="verdana"><b>YY , Have a Nice day :) - From LZ</b></font>';
  24. txt.x = stage.stageWidth - txt.textWidth;
  25. txt.y = stage.stageHeight - txt.textHeight;
  26. txt.width = txt.textWidth+10;
  27. txt.selectable = false;
  28. addChild(txt);
  29. }
  30. }
  31.  
  32. function clearKeys(evt)
  33. {
  34. keyDowns = '';
  35. }

Report this snippet  

You need to login to post a comment.