RE: [flexcoders] Re: How to get the real X Y of a repeater item

2007-02-27 Thread Gordon Smith
Here is a sample app which does what you describe.
 
- Gordon
 
?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml;
 
mx:Script![CDATA[

import mx.containers.Canvas;
import mx.containers.TitleWindow;
import mx.controls.Button;
import mx.managers.PopUpManager;
  
private var popUp:TitleWindow;
  
private function b_clickHandler(event:MouseEvent):void
{
var b:Button = Button(event.target);
var pt:Point = b.localToGlobal(new Point(0, 0)); // global
coords of b's top-left corner
// var pt:Point = vb.localToGlobal(new Point(b.x, b.y)); //
another way to compute the global coords of b's top-left corner
createPopUp(pt.x, pt.y + b.height + 2);
}
  
private function createPopUp(x:Number, y:Number):void
{
popUp = new TitleWindow();
   
popUp.x = x;
popUp.y = y;
popUp.width = 100;
popUp.height = 100;
popUp.title = Panel;
popUp.setStyle(styleName, opaquePanel);
popUp.showCloseButton = true;
popUp.addEventListener(Event.CLOSE, popupCloseHandler);
   
PopUpManager.addPopUp(popUp, this);
}
  
private function popupCloseHandler(event:Event):void
{
PopUpManager.removePopUp(popUp);
popUp = null;
}
  
]]/mx:Script
 
mx:VBox
mx:TabNavigator width=300 height=200
mx:VBox id=vb label=Tab 1
mx:Repeater id=r dataProvider={[ 1, 2, 3 ]}
mx:Button id=b label=Button {r.currentItem}
click=b_clickHandler(event)/
/mx:Repeater
/mx:VBox
/mx:TabNavigator
/mx:VBox
 
/mx:Application



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of zipo13
Sent: Sunday, February 25, 2007 1:18 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: How to get the real X  Y of a repeater item



Hi,
Thank you for the help but non of these methods seem to help.
The repeater I use is in a canvas that sits in a tab navigator that
sits in a vbox in an application.
All in different components.

I have tried to open the dialog:
var pt:Point = new Point(event.stageX, event.stageY);
pt = event.target.contentToGlobal(pt);
this.renameTagDlg.x = pt.x;//
this.renameTagDlg.y = pt.y;//

I've changed the contentToLocal to all 6 possibilities but none of
them work. 
contentToGlobal,contentToLocal,globalToContent,globalToLocal,localToCont
ent,localToGlobal

I have even tried to get the X,Y of the mouse globalyy and just open
the dialog there but that didn't work too.

I think that jer_ela was on the right track but I just can subtract
all the containers X  Y.

THIS IS SO FRUSTRATING. 

--- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com
, Robert Chyko [EMAIL PROTECTED] wrote:

 or if your container uses absolute positioning you would need to use
 contentToGlobal
 
 
 -Original Message-
 From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com

 [mailto:flexcoders@yahoogroups.com
mailto:flexcoders%40yahoogroups.com ] On Behalf Of Keun Lee
 Sent: Friday, February 23, 2007 2:09 PM
 To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com 
 Subject: Re: [flexcoders] Re: How to get the real X  Y of a
 repeater item
 
 
 
 Hey you might want to also look into localToGlobal 
 
 I.e
 
 var comp : UIComponent = UIComponent(
 event.target ); var point : Point = comp.localToGlobal(
 new Point( comp.x, comp.y ) ); trace( point.x + : +
 point.y );
 
 -Keun
 
 
 On 2/22/07 9:24 AM, jer_ela [EMAIL PROTECTED] wrote:
 
 
 
 
 
 
 
 The following code gets the x and y positions of an
 image that has
 been clicked on that was generated by a repeater.
 Getting the coords
 for a button should be pretty much the same. 
 
 stageX and Y are the x and y coords of the mouse
 position relative to
 the application stage. mainCanvas is a direct child of
 the application
 and is the container that I want the coords relative to.
 If you have
 additional containers between the stage and the one you
 need coords
 relative to, you have to subtract the x and y at each
 level to get
 from stage coords to that container's coords.
 Subtracting the mouseX
 and Y moves the coords from the point or the click to
 the upper left
 corner of the image.
 
 selectedImage.x = event[stageX] - mainCanvas.x 
 - event.currentTarget.mouseX;
 selectedImage.y = event[stageY] - mainCanvas.y 
 - event.currentTarget.mouseY;
 
 --- In flexcoders@yahoogroups.com
mailto:flexcoders%40yahoogroups.com 
 mailto:flexcoders%40yahoogroups.com
 mailto:flexcoders%40yahoogroups.com , zipo13 zipo13@ wrote:
 
  Hi,
  In my app I create a repeater the generats VBoxes each
 with button
 in it.
  When the user clicks on the button I want to generate
 a small dialog
  that will open up under the button

Re: [flexcoders] Re: How to get the real X Y of a repeater item

2007-02-23 Thread Keun Lee
Hey you might want to also look into ³localToGlobal²

I.e

var comp : UIComponent = UIComponent( event.target );
var point : Point = comp.localToGlobal( new Point( comp.x, comp.y ) );
trace( point.x + : +  point.y );

-Keun


On 2/22/07 9:24 AM, jer_ela [EMAIL PROTECTED] wrote:

  
  
  
 
 The following code gets the x and y positions of an image that has
 been clicked on that was generated by a repeater.  Getting the coords
 for a button should be pretty much the same.
 
 stageX and Y are the x and y coords of the mouse position relative to
 the application stage. mainCanvas is a direct child of the application
 and is the container that I want the coords relative to.  If you have
 additional containers between the stage and the one you need coords
 relative to, you have to subtract the x and y at each level to get
 from stage coords to that container's coords.  Subtracting the mouseX
 and Y moves the coords from the point or the click to the upper left
 corner of the image.
 
 selectedImage.x = event[stageX] - mainCanvas.x
  - event.currentTarget.mouseX;
 selectedImage.y = event[stageY] - mainCanvas.y
  - event.currentTarget.mouseY;
 
 --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ,
 zipo13 [EMAIL PROTECTED] wrote:
 
  Hi,
  In my app I create a repeater the generats VBoxes each with button
 in it.
  When the user clicks on the button I want to generate a small dialog
  that will open up under the button.
  I know how to get the repeater current item and target and current
  target but I can't find the real X  Y of the button.
  Am I going in the wrong direction?
 
 
  
 




RE: [flexcoders] Re: How to get the real X Y of a repeater item

2007-02-23 Thread Robert Chyko
or if your container uses absolute positioning you would need to use
contentToGlobal
 

-Original Message-
From: flexcoders@yahoogroups.com
[mailto:[EMAIL PROTECTED] On Behalf Of Keun Lee
Sent: Friday, February 23, 2007 2:09 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Re: How to get the real X  Y of a
repeater item



Hey you might want to also look into localToGlobal 

I.e

var comp : UIComponent = UIComponent(
event.target );var point : Point = comp.localToGlobal(
new Point( comp.x, comp.y ) );trace( point.x + : +
point.y );

-Keun


On 2/22/07 9:24 AM, jer_ela [EMAIL PROTECTED] wrote:




 
 

The following code gets the x and y positions of an
image that has
been clicked on that was generated by a repeater.
Getting the coords
for a button should be pretty much the same.  

stageX and Y are the x and y coords of the mouse
position relative to
the application stage. mainCanvas is a direct child of
the application
and is the container that I want the coords relative to.
If you have
additional containers between the stage and the one you
need coords
relative to, you have to subtract the x and y at each
level to get
from stage coords to that container's coords.
Subtracting the mouseX
and Y moves the coords from the point or the click to
the upper left
corner of the image.

selectedImage.x = event[stageX] - mainCanvas.x 
 - event.currentTarget.mouseX;
selectedImage.y = event[stageY] - mainCanvas.y 
 - event.currentTarget.mouseY;

--- In flexcoders@yahoogroups.com
mailto:flexcoders%40yahoogroups.com
mailto:flexcoders%40yahoogroups.com  , zipo13 [EMAIL PROTECTED] wrote:

 Hi,
 In my app I create a repeater the generats VBoxes each
with button
in it.
 When the user clicks on the button I want to generate
a small dialog
 that will open up under the button.
 I know how to get the repeater current item and target
and current
 target but I can't find the real X  Y of the button.
 Am I going in the wrong direction?