I was not in my topmost application
file.... I was inside a custom component file, that was being called by another
custom component, which was called by the topmost application file.
So, in theory, "this" should
have referred to the proper code. In fact, the same code (minus the changes for
Point vs Object) in 1.5 produces the expected result.
Shan
From:
[EMAIL PROTECTED]ups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Gordon Smith
Sent: Tuesday, August 08, 2006
3:27 PM
To: [EMAIL PROTECTED]ups.com
Subject: RE: [flexcoders] Finding
the x/y position of an object
>Well, for some reason when I specify "this" it always
referred to the application, not the object I was trying to get the x/y of
Understanding what 'this' refers to is very important when
writing Flex code. All the 'this' references in a particular MXML document --
whether inside a <mx:Script> block or in event handler attributes on tags
-- refer to the same "document object", the one represented by the
topmost tag in the MXML file. If you are in MyApplication.mxml, 'this' is
always a reference to the instance of MyApplication. If you are in MyComponent,
'this' is always a reference to the instance of MyComponent.
- Gordon
From: [EMAIL PROTECTED]ups.com [mailto:flexcoders@yahoogroups.com]
On Behalf Of Shannon Hicks
Sent: Tuesday, August 08, 2006
1:17 PM
To: [EMAIL PROTECTED]ups.com
Subject: RE: [flexcoders] Finding
the x/y position of an object
Well, for some reason when I specify "this" it always
referred to the application, not the object I was trying to get the x/y of.
Here's the fixed code:
private function
doThis(event:Event): void {
var pt:Point = new
Point(0,0);
pt = event.target.contentToGlobal(pt);
}
Shan
From: [EMAIL PROTECTED]ups.com [mailto:flexcoders@yahoogroups.com]
On Behalf Of Gordon Smith
Sent: Tuesday, August 08, 2006
3:10 PM
To: [EMAIL PROTECTED]ups.com
Subject: RE: [flexcoders] Finding
the x/y position of an object
Are your code snippets in the app file, where 'this' is a reference
to the application? Or did you make an MXML component based on HBox and the
code snippets are from it so that 'this' is the nested object? In neither case
does it look like the right logic to me.
In an application script, I think you want to do
var pt:Point = new Point(0, 0); // position
of nestedObject in its own coordinates (i.e., nestedObject's coordinates)
pt = nestedObject.localToGlobal(pt) //
position of nestedObject in global coordinates
or (more complicated and not recommended)
var pt:Point = new Point(nestedObject.x,
nestedObject.y); // position of nestedObject in its parent's coordinates
(i.e., nestedObject.parent's coordinates)
pt = nestedObject.parent.localToGlobal(pt)
// position of nestedObject in global coordinates
Note that localToGlobal() returns a new Point; it
doesn't change the Point passed in.
- Gordon
From: [EMAIL PROTECTED]ups.com [mailto:flexcoders@yahoogroups.com]
On Behalf Of Shannon Hicks
Sent: Tuesday, August 08, 2006
9:18 AM
To: [EMAIL PROTECTED]ups.com
Subject: [flexcoders] Finding the
x/y position of an object
I have a
nested object (an HBox) in my app, and I'm trying to figure out the global x/y
position of it.
var pt:Point = new Point(this.x,this.y);
this.localToGlobal(pt);
But
it always returns 0/0. Even if I do this:
var pt:Point = new Point(parent.x,parent.y);
this.localToGlobal(pt);
It's
returning an odd value, like 0/90.... the actual x/y position of the object is
somewhere around 350/275
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.10.7/411 - Release Date: 8/7/2006
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.10.7/411 - Release Date: 8/7/2006
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.10.7/411 - Release Date: 8/7/2006
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.10.7/411 - Release Date: 8/7/2006
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.10.7/411 - Release Date: 8/7/2006