This should give you an idea:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="onCreationComplete(event)">
<mx:Script>
<![CDATA[
import mx.controls.Button;
import mx.containers.GridItem;
import mx.containers.GridRow;
import mx.containers.Grid;
import mx.events.FlexEvent;
import mx.controls.Alert;
private var buttonsArray:Array = new Array("One", "two",
"Three", "Four", "Five", "Six", "Seven", "Eight", "Nine");
private var myGridRow:GridRow;
private var myButton:Button;
private function onCreationComplete(event:FlexEvent):void
{
var myGrid:Grid = new Grid();
for(var i:int = 0 ; i < buttonsArray.length ; i++)
{
var myGridItem:GridItem = new GridItem();
myButton = new Button();
myButton.label = buttonsArray[i];
myButton.addEventListener(MouseEvent.CLICK,
buttonWasClicked);
myGridItem.addChild(myButton);
if((i % 3) == 0 || i == 0)
{
if(i != 0)
{
myGrid.addChild(myGridRow);
}
myGridRow = new GridRow();
}
myGridRow.addChild(myGridItem);
}
myGrid.addChild(myGridRow);
this.addChild(myGrid);
}
private function buttonWasClicked(event:MouseEvent):void
{
var currentButton:Button = event.target as Button;
var pt:Point = new Point(currentButton.x,
currentButton.y);
pt = event.target.localToGlobal(pt);
Alert.show("Clicked Button Left: " + pt.x + "\n" +
"Clicked Button Bottom: " + (pt.y + currentButton.height).toString());
}
]]>
</mx:Script>
</mx:Application>
> > -----Original Message-----
> > From: [email protected]
<mailto:flexcoders%40yahoogroups.com> on behalf of pbrendanc
> > Sent: Thu 26/06/2008 7:55 PM
> > To: [email protected] <mailto:flexcoders%40yahoogroups.com>
> > Subject: [flexcoders] How to Position a Popup relative to the
> control that invoked the popup?
> >
> > I have a grid with an array of buttons that when clicked, will
display
> > a popup window that collects user info.
> > What I'd like to do is position the popup relative (immediately
below)
> > the button that the user clicked within the grid - not necessarily
> > centered on the current window.
> >
> > How can I get access the position/coordinates of the calling button
-
> > is this data somehow available via the createComplete event of the
> > popup. I imagine this data is buried somewhere in the
> > event/eventtarget object, but I'm not quite sure how to access it.
> >
> > (Please don't tell me that I need to assign a listener to every
button
> > in the grid from within the Popup window as I'm creating the grid
> > dynamically and it varies in size).
> >
> > Can anyone help with this,
> >
> > TIA,
> > Patrick