Created
July 5, 2012 07:15
-
-
Save sspecht/3051975 to your computer and use it in GitHub Desktop.
Event-Listener Beispiel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import flash.display.DisplayObject; | |
import flash.display.SimpleButton; | |
import flash.display.Sprite; | |
import flash.events.MouseEvent; | |
public class EventListenerExample extends Sprite | |
{ | |
public var knoepfe:Array = ["knopf1", "knopf2", "knopf3", "knopf4"]; | |
// constructor | |
public function EventListenerExample() | |
{ | |
super(); | |
} | |
// Knöpfe anlegen | |
private function setupButtons():void { | |
for (var i:int = 0; i < knoepfe.length; i++) { | |
// SimpleButton ist nur ein Beispiel, darum geht es hier nicht | |
var knopf:SimpleButton = new SimpleButton(); | |
knopf.name = knoepfe[i]; | |
knopf.addEventListener(MouseEvent.CLICK, ausgabe ); | |
addChild(knopf); | |
} | |
} | |
private function ausgabe(e:MouseEvent):void | |
{ | |
var knopf:DisplayObject; | |
knopf = e.target as DisplayObject; | |
if (knopf) trace( "target: " + knopf.name ); | |
knopf = e.currentTarget as DisplayObject; | |
if (knopf) trace( "currentTarget: " + knopf.name ); | |
knopf = e.relatedObject as DisplayObject; | |
if (knopf) trace( "relatedObject: " + knopf.name ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment