Hallo,
ich hab wiedermal ein komisches Problem:
ActionScript:
public function MainClass()
{
trace("MainClass: this: " + this +" - " + getQualifiedClassName(this));
addEventListener(FlexEvent.INITIALIZE, test);
}
public function test(e:Event = null):void
{
trace("test: this: " + this +" - " + getQualifiedClassName(this));
var c:Button = new Button();
c.addEventListener(FlexEvent.INITIALIZE, function(evt:Event):void
{
trace("FlexEvent.INITIALIZE: this: " + this +" - " + getQualifiedClassName(this));
});
c.addEventListener(MouseEvent.CLICK, function(evt:Event):void
{
trace("MouseEvent.CLICK: this: " + this +" - " + getQualifiedClassName(this));
});
addChild(c);
}
Ich würde ja annehmen, dass dieser Code bei allen Trace als
this-Klasse "Main" ausgeben würde. Macht er aber nicht:
Code:
MainClass: this: Main0 - Main
test: this: Main0 - Main
FlexEvent.INITIALIZE: this: [object global] - global
MouseEvent.CLICK: this: [object global] - global
Warum ist
this in dem (anonymen) Eventhandler auf einmal "
global" und im Eventhandler
test wie gewünscht?!
Lg
Warappa
Flashdevelop 3
Flex 3 Projekt