tags:

views:

31

answers:

1

In felx, how to send the id of the component ( on which the mouse pointer is clicked ) to a function with the mouse click?

+2  A: 

The event object that your handler receives will have the id in the event.target property.

Gregor Kiddie
what I see is that : design0.mainBox.Canvas28.VBox29.HBox30.HBox33.Label34.UITextField35But I set the id hb1 but I dont see that anywhere? Don't it use the id specified by the programmer?
from hb1 I expect you think you're clicking on an HBox? Remember that anything in the HBox will sit above it in the display list and capture the click event before their parents. In your comment, it looks like a Label is what's seeing the click first.
Gregor Kiddie
thats ok !!! the thing is instead of hb1, Im getting HBox33 ( automaticall being generated ).
It doesn't look like your HBox in in the parent stack for that label then. Given that you are sticking things on a canvas, are they overlapping?
Gregor Kiddie
No. design0.mainBox is correct but Canvas28 is not specified by me. The only different thing is I am using <mx:AddChild relativeTo="{mainBox}"> to add the canvas.
<mx:HBox id="meraBox" backgroundColor="#FA6127" color="white" horizontalGap="0" click="imageClick(event)">so, if I get event.target, doesnt it should show the id as meraBox? But it shows HBox33
Are you re-parenting everything when you add in the Canvas? I'm not sure of what you are doing from the snippits, but Flex is either losing the id when you re-parent (If that's what you are doing) in which case, it's probably a bug, or you are laying stuff on top of your HBox so it's not in the stack.If you do stage.getObjectsUnderPoint(new Point(event.mouseX, event.mouseY)) in your event handler and look through the array, does your HBox appear in it? If so you've got something lying over it, if not, something is renaming it.
Gregor Kiddie
I am not seeing the id specified by me.
erm sorry, try stage.getObjectsUnderPoint(new Point(stage.mouseX, stage.mouseY)) forgot the x and y weren't in the same targetspace...
Gregor Kiddie
Yea, I did the same. But I dont see it.
The interesting thing is that if I use ( like var elem:Label = this["HBox33"]; ) the id shown by event.target, it shows error that it does not exist But if I use id used by me, it works fine. But, my issue is I cannot determine which HBo is clicked?
yeah... I'm a moron... it's giving you the name of the component, not the id.
Gregor Kiddie
:) yea ... thatz name.. thanks !!!