RSS
 

Event handler not triggered trotz addEventListener

03 Nov

Versucht man in der Flash CS4-Autorenumgebung einen Keyhandler onKeyUp hinzuzufügen, so kann es passieren, dass der folgende Fehler auftaucht, obwohl man die Funktion mittels addEventListener hinzugefügt hat: Warning: 1090: Migration issue: The onKeyUp event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( 'keyUp', callback_handler).

Des Rätsels Lösung liegt ganz einfach in der Benamung der Funktion. onKeyUp wird, wie das Syntaxhighlighting auch schon andeutet, als Schlüsselwort behandelt und kann daher nicht für die Funktion verwendet werden. Kaum ändert man den Funktionsnamen läft es fehlerfrei.

stage.addEventListener(KeyboardEvent.KEY_UP, doKeyUp);
function doKeyUp(event:KeyboardEvent):void
{
   switch(event.keyCode)
   {
      case Keyboard.RIGHT:
         nextFrame();
      break;
      case Keyboard.LEFT:
         if (currentFrame>2) prevFrame();
      break;
   }
}
 
No Comments

Posted in Flash

 

Leave a Reply

 

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word