2bam

GameInput order-of-addition bug sample code

Jan 7th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  {
  2.     import flash.display.Sprite;
  3.     import flash.events.Event;
  4.     import flash.events.GameInputEvent;
  5.     import flash.text.TextField;
  6.     import flash.text.TextFormat;
  7.     import flash.ui.GameInput;
  8.     import flash.ui.GameInputDevice;
  9.     /**
  10.      * ...
  11.      * @author 2bam.com
  12.      */
  13.     public class Main extends Sprite {
  14.        
  15.         private var _tf:TextField;
  16.         private var _gi:GameInput;
  17.         private var _myCount:int = 0;
  18.        
  19.         private function onAdd(ev:GameInputEvent):void {
  20.             _myCount++;
  21.         }
  22.        
  23.         private function onRem(ev:GameInputEvent):void {
  24.             _myCount--;
  25.         }
  26.        
  27.         private function onFrame(ev:Event):void {
  28.             var s:String;
  29.             s = "GameInput "+(GameInput.isSupported?"":"NOT")+" supported\n";
  30.             s += "GameInput.numDevices = "+GameInput.numDevices+"\n";
  31.             s += "_myCount = "+_myCount+"\n";
  32.             for(var i:int = 0; i<GameInput.numDevices; i++) {
  33.                 var dev:GameInputDevice = GameInput.getDeviceAt(i);
  34.                 s += "======="+i+"=======\n";
  35.                 s += "\tname: "+dev.name+"\n";
  36.                 s += "\t  id: "+dev.id+"\n";
  37.             }
  38.             _tf.text = s;
  39.         }
  40.        
  41.        
  42.         public function Main() {
  43.             _tf = new TextField;
  44.             _tf.multiline = true;
  45.             _tf.wordWrap = true;
  46.             _tf.defaultTextFormat = new TextFormat("Courier New", 16);
  47.             _tf.width = stage.stageWidth;
  48.             _tf.height = stage.stageHeight;
  49.             addChild(_tf);
  50.             stage.addEventListener(Event.ENTER_FRAME, onFrame);
  51.            
  52.             _gi = new GameInput;
  53.             _gi.addEventListener(GameInputEvent.DEVICE_ADDED, onAdd,false,0,true);
  54.             _gi.addEventListener(GameInputEvent.DEVICE_REMOVED, onRem,false,0,true);
  55.         }
  56.        
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment