Ahh.. I was confused because what you really want to know is, "Given an
String specifying a component's id, how do I get a reference to that
component?"
 
The answer to that is to use this[id]:
 
    var id:String = "ti_2";
    var textInput:TextInput = this[id];
 
Of course, once you have a reference to a component, you can get its
position or any other property.
 
- Gordon

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of flexawesome
Sent: Wednesday, September 12, 2007 1:27 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: How to get Textinput position?




Hey Gordon,

I am appreciate for your promptly response, sorry for my confusion. I
mean if I know the id name for the textInput, is there a way to click
the button to get the position for "ti_2"?

Have a nice day :)

=================================
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> ">

<mx:Script>
<![CDATA[

import mx.controls.Alert;

private function createMsg(event:Event):void
{
var topLeft:Point = new Point(0, 0);
topLeft = event.currentTarget.localToGlobal(topLeft);
Alert.show("the X position of the top left of LABEL 1 in
global coordinates is " + topLeft.x, "Show Me", Alert.YES | Alert.NO);
}

]]>
</mx:Script>

<mx:Panel>
<mx:Form>
<mx:FormItem label="Label1">
<mx:TextInput id="ti_1" />
</mx:FormItem>
<mx:FormItem label="Label2">
<mx:TextInput id="ti_2" />
</mx:FormItem>
<mx:FormItem label="Label3">
<mx:TextInput id="ti_3" />
</mx:FormItem>

<mx:Button label="Button" click="createMsg(event);"/>

</mx:Form>
</mx:Panel>

</mx:Application>
====================================================

--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
, "Gordon Smith" <[EMAIL PROTECTED]> wrote:
>
> I wish I could understand what you don't understand. Here's a complete
> working example.
> 
> - Gordon
> 
> <?xml version="1.0"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> ">
> 
> <mx:Script>
> <![CDATA[
> 
> import mx.controls.Alert;
> 
> private function createMsg(event:Event):void
> {
> var topLeft:Point = new Point(0, 0);
> topLeft = event.currentTarget.localToGlobal(topLeft);
> Alert.show("the X position of the top left of LABEL 1 in
> global coordinates is " + topLeft.x, "Show Me", Alert.YES | Alert.NO);
> }
> 
> ]]>
> </mx:Script>
> 
> <mx:Panel>
> <mx:Form>
> <mx:FormItem label="Label1">
> <mx:TextInput focusOut="createMsg(event);"/>
> </mx:FormItem>
> <mx:FormItem label="Label2">
> <mx:TextInput/>
> </mx:FormItem>
> <mx:FormItem label="Label3">
> <mx:TextInput/>
> </mx:FormItem>
> </mx:Form>
> </mx:Panel>
> 
> </mx:Application>
> 
> ________________________________
> 
> From: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
[mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of flexawesome
> Sent: Wednesday, September 12, 2007 9:43 AM
> To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> 
> Subject: [flexcoders] Re: How to get Textinput position?
> 
> 
> 
> great, I see.... but I was serious how to get a textInput position in
> form ( id=textInput ) by click the button?
> 
> for example like coding below? huummm....
> 
> evt.currentTarget.parent.localToGlobal (new
> Point(evt.currentTarget.x,evt.target.textInput.y)).y 
> 
> Cheers
> 
> --- In flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com>
> , "Gordon Smith" <gosmith@> wrote:
> >
> > Assuming that what you want is global coordinates, it's even simpler
> to
> > do
> > 
> > event.currentTarget.localToGlobal(new Point(0, 0)).x
> > 
> > which works because the upper-left of any component is (0, 0) in its
> own
> > local coordinate system.
> > 
> > - Gordon
> > 
> > ________________________________
> > 
> > From: flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com>
> [mailto:flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com>
> ] On
> > Behalf Of flexawesome
> > Sent: Tuesday, September 11, 2007 8:32 AM
> > To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com> 
> > Subject: [flexcoders] Re: How to get Textinput position?
> > 
> > 
> > 
> > you are SO COOL. Thank you so much :)
> > 
> > have a nice day
> > 
> > --- In flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com>
> <mailto:flexcoders%40yahoogroups.com>
> > , "Sven Woermann" <sven.woermann@>
> > wrote:
> > >
> > > Hi, try this. You are basically calling the localToGlobal method
on
> > the
> > > parent container of the TextInput and give it the position of the
> > TextInput
> > > relative to it's parent.
> > > 
> > > event.currentTarget.parent.localToGlobal(new
> > Point(event.currentTarget.x,
> > > event.currentTarget.y)).x
> > > 
> > > 
> > > 
> > > 
> > > On 9/11/07, flexawesome <flexawesome@> wrote:
> > > >
> > > >
> > > > Hi Gordeon,
> > > >
> > > > Thank you so much to reply it as I am new to flex, and don't
know
> > how
> > > > to use localToGlobal() it in my app below, I am appreciate if
you
> > > > can show me the code , that would be great!
> > > >
> > > > THANKS :)
> > > >
> > > >
> > > > --- In flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com> 
> > <mailto:flexcoders%40yahoogroups.com>
<flexcoders%40yahoogroups.com>,
> > "Gordon
> > > > Smith" <gosmith@> wrote:
> > > > >
> > > > > The x and y properties of a DisplayObject are in the
coordinate
> > > > system
> > > > > of its parent. So you're getting the location of the top-left
of
> > the
> > > > > TextInput relative to the top-left of the FormItem. If you
want
> > > > > coordinates in a different coordinate system, use
> localToGlobal()
> > > > and
> > > > > globalToLocal().
> > > > >
> > > > > - Gordon
> > > > >
> > > > > ________________________________
> > > > >
> > > > > From: flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com> 
> > <mailto:flexcoders%40yahoogroups.com> <flexcoders%40yahoogroups.com>
> > > > [mailto:flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com> 
> > <mailto:flexcoders%40yahoogroups.com>
<flexcoders%40yahoogroups.com>]
> > On
> > > > > Behalf Of flexawesome
> > > > > Sent: Monday, September 10, 2007 7:11 PM
> > > > > To: flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com> 
> > <mailto:flexcoders%40yahoogroups.com> <flexcoders%40yahoogroups.com>
> > > > > Subject: [flexcoders] Re: How to get Textinput position?
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > humm...parent doesn't work... and I correct the code below..
> > > > >
> > > > > Cheers
> > > > >
> > > > > ================================
> > > > >
> > > > > <?xml version="1.0"?>
> > > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> 
> <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > 
> > <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml>
<http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > > 
> > > > > <http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml>  <http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> >
> <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml>
<http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > > >
> > "
> > > > > viewSourceURL="srcview/index.html">
> > > > > <mx:Script>
> > > > > <![CDATA[
> > > > >
> > > > > import mx.core.IFlexDisplayObject;
> > > > > import mx.core.UIComponent;
> > > > > import mx.controls.Alert;
> > > > >
> > > > > private function createMsg(event:Event):void {
> > > > >
> > > > > var target:UIComponent = UIComponent(event.currentTarget);
> > > > >
> > > > > var alert:Alert;
> > > > >
> > > > > Alert.show("the X position of LABEL 1 is
> "+event.currentTarget.x,
> > > > > "Show Me", Alert.YES | Alert.NO)
> > > > > }
> > > > >
> > > > > ]]>
> > > > > </mx:Script>
> > > > >
> > > > > <mx:Panel>
> > > > > <mx:Form>
> > > > > <mx:FormItem label="Label1">
> > > > > <mx:TextInput focusOut="createMsg(event);"/>
> > > > > </mx:FormItem>
> > > > > <mx:FormItem label="Label2">
> > > > > <mx:TextInput/>
> > > > > </mx:FormItem>
> > > > > <mx:FormItem label="Label3">
> > > > > <mx:TextInput/>
> > > > > </mx:FormItem>
> > > > > </mx:Form>
> > > > > </mx:Panel>
> > > > >
> > > > > </mx:Application>
> > > > >
> > > > > --- In flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com> 
> > <mailto:flexcoders%40yahoogroups.com> 
> > <flexcoders%40yahoogroups.com><mailto:
> > > > flexcoders% <flexcoders%25>
> > > > 40yahoogroups.com>
> > > > > , "Alex Harui" <aharui@> wrote:
> > > > > >
> > > > > > Might be event.currentTarget.parent.x. There is no Label1 in
> > your
> > > > > > sample. Also see localToGlobal
> > > > > >
> > > > > >
> > > > > >
> > > > > > ________________________________
> > > > > >
> > > > > > From: flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com> 
> > <mailto:flexcoders%40yahoogroups.com> 
> > <flexcoders%40yahoogroups.com><mailto:
> > > > flexcoders% <flexcoders%25>
> > > > 40yahoogroups.com>
> > > > >
> > > > > [mailto:flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com> 
> > <mailto:flexcoders%40yahoogroups.com> 
> > <flexcoders%40yahoogroups.com><mailto:
> > > > flexcoders% <flexcoders%25>
> > > > 40yahoogroups.com>
> > > > > ] On
> > > > > > Behalf Of flexawesome
> > > > > > Sent: Monday, September 10, 2007 11:43 AM
> > > > > > To: flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com> 
> > <mailto:flexcoders%40yahoogroups.com> <flexcoders%40yahoogroups.com>
> > <mailto:
> > > > flexcoders% <flexcoders%25>
> > > > 40yahoogroups.com>
> > > > > > Subject: [flexcoders] How to get Textinput position?
> > > > > >
> > > > > >
> > > > > >
> > > > > > Hi guys.... :)
> > > > > >
> > > > > > I am working on flex, and looks hard to get the target
object
> x
> > > > and
> > > > > y
> > > > > > position. do you have any ideas?
> > > > > >
> > > > > > Cheers & THANKS
> > > > > >
> > > > > > ================================
> > > > > >
> > > > > > <?xml version="1.0"?>
> > > > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> 
> <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > 
> > <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml>
<http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > > 
> > > > > <http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml>  <http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> >
> <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml>
<http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > > >
> > > > > > <http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> 
> <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> >
<http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> 
> <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > >
> > <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml>
<http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> >
> <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml>
<http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > > >
> > > > > "
> > > > > > viewSourceURL="srcview/index.html">
> > > > > > <mx:Script>
> > > > > > <![CDATA[
> > > > > >
> > > > > > import mx.core.IFlexDisplayObject;
> > > > > > import mx.core.UIComponent;
> > > > > > import mx.controls.Alert;
> > > > > >
> > > > > >
> > > > > > private function createMsg(event:Event):void {
> > > > > >
> > > > > > var target:UIComponent = UIComponent(event.currentTarget);
> > > > > >
> > > > > > var alert:Alert;
> > > > > >
> > > > > > Alert.show("the X position of LABEL 1 is
> > "+event.currentTarget.x,
> > > > > > "Show Me", Alert.YES | Alert.NO)
> > > > > > }
> > > > > >
> > > > > > ]]>
> > > > > > </mx:Script>
> > > > > >
> > > > > > <mx:Panel>
> > > > > > <mx:Form>
> > > > > > <mx:FormItem label="Label">
> > > > > > <mx:TextInput focusOut="createMsg(event);"/>
> > > > > > </mx:FormItem>
> > > > > > <mx:FormItem label="Label">
> > > > > > <mx:TextInput/>
> > > > > > </mx:FormItem>
> > > > > > <mx:FormItem label="Labe3">
> > > > > > <mx:TextInput/>
> > > > > > </mx:FormItem>
> > > > > > </mx:Form>
> > > > > > </mx:Panel>
> > > > > >
> > > > > > </mx:Application>
> > > > > >
> > > > >
> > > >
> > > > 
> > > >
> > >
> >
>



 

Reply via email to