PDA

View Full Version : MouseEvent on UIComponent


mitchel456
04-21-2009, 05:53 AM
Okay, I'd been puzzling over a problem I'm having with Flex for a while now, and at this point, either there's something I'm fundamentally misunderstanding about the Flex/ActionScript event model, or I'm making a really silly mistake that's going to make me feel really dumb when somebody points it out ;)

I'm trying to attach a MouseEvent listener to a UIComponent (which will hold a Papervision3D scene that'll be manipulated by these events, but that's getting ahead of myself). Right now I'm trying to set up a minimal test case - when I attach the listener with this.addEventListener(...), clicks are registered when I click anywhere on the screen (as expected), but when I attach the event listener to the UIComponent as below, no clicks are registered, within the boundaries of the UIComponent or otherwise. Here's my code - am I overlooking something really silly? I can't figure out why this isn't working. Thanks in advance for any help:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" layout="absolute">
<mx:Script>
<![CDATA[
private var test:TestEvents = new TestEvents();
private function init():void {
//testComponent.addChild(test);
testComponent.addEventListener(MouseEvent.CLICK, testClick);
trace("testComponent width: " + testComponent.width);
trace("testComponent height: " + testComponent.height);
}
private function testClick(event:MouseEvent):void {
trace("Click: " + new Date());
}
]]>
</mx:Script>
<mx:HBox width="500" height="400" backgroundColor="#000000">
<mx:UIComponent id="testComponent" width="500" height="400"/>
</mx:HBox>
</mx:Application>

Ryan