Displaying x,y coordinates

hi | i’m in the midst of creating a draggable movie clip with a display screen. the screen will show the current x,y coordinates of the clip. i’m not sure how to go about doing this. anyone have any ideas?

thanks, fu-meng.

what about trying the following code on frame 1 of your movieclip

this.x = this._x;
this.y = this._y;

and then putting two dynamic text boxes on your movieclip stage and enter x and y into the respective variable fields in the property inspector panel.

…maybe i’m missing the point of what you’re trying to do.

Well, not exactly, segar :slight_smile:

If your scene contains:[list][]one clip, instance name myClip
[
]2 textFields, instance name xPos and yPos[/list]Then you should put this code in the first frame of your movie:

myClip.startDrag();
this.onEnterFrame=function(){
  xPos.text=myClip._x;
  yPos.text=myClip._y;
}

pom :beam:

yep

hi everyone | first of all, thank you all for your very quick help. i just picked up a rather large and complicated and pressing actionscript project this week and am just getting started. rynoe, the .fla you posted worked for me but i have one quick question. i want to display the tenths and hundredths position in the coordinates. how do i do that? obviously, Math.round rounds it off. how can i get around that?

thanks. - matt.

First you must answer me these questions 3!
question 1:

How many fractions are between the numbers 1 and 2?

there’s an infinite number of possibilities depending on how small you want to break up the distance between them.

Very good!
Now, because there is no number format function in actionscript, at least that I am aware of, as there is in other languages(keep that in mind).

Can we specifically format a dynamic number to the 100ths position?

*Originally posted by rynoe *
**First you must answer me these questions 3!
question 1:

How many fractions are between the numbers 1 and 2? **

What is your quest?

fumeng: you cant get the tenths or hundredths of those values because there are none. for every pixel your mouse moves is one unit of measure in flash. The only reason Math.round() would be needed is if you didnt place the clip directly on a whole number to begin with, in which case, each subsequent value would continue to have that same fraction offset added to it.

the only time fractions would come into play is if the clip your clip in question is in scaled or if the movie itself wasnt played at normal size. At that point the measurement (pixels) is stretched so each pixel your mouse moves would be different then flashes interpretation of what a pixels distance is. Then its a simple matter of rounding to what place you want your precision to be. ie:

num = 12345.6789
num = Math.round(num*100)/100
trace(num) // traces 12345.67

this technique of */ will let you round to whatever place you want

Sorry that is the wrong answer. Down the pit you go!
Too bad the next question was what is your favorite color.

I didint want to be stuck with the “What is the air-speed velocity of an unladen swallow” question :stuck_out_tongue:

:slight_smile:

What kind of swallow: African or European?

… well I dont know

whooooooooooooooooeeeeeeeeeeee

Alright I tried some things but after a while I remembered a character billy crystal did and I quote
“It is better to look good than feel good”
So I just cheated.

hello senocular | it’s confusing, but i think i’m beginning to understand. i do understand that i can’t “really” get the true tenths or hundredths position because they don’t exist, but i can fake it by running a random number variable and throwing it in. my question is how i integrate the code you gave me with my own. i think i have it almost right. would you mind taking a quick look, please?

onClipEvent(mouseMove){
num = .12
num = Math.round(num*100)/100

            x=Math.round(this._x + num);
y=Math.round(this._y + num);

}

does it look close?

thanks. - matt.

:beam:

I have been laughing reading those posts, and it reminded me of a time that I was walking into class at my local community college. Out of nowhere, I hear this clunking noise and look behind me to see my good friend Thomas with , what looked like two coconut halves. OH MY GOSH WAS IT HILARIOUS!

Even funnier, was seeing the scarce amount of people know what the heck he was doing. It was great.

:crazy:

if you want to fake it, I wouldnt use just .12, Id use a random number

Math.round(num*100)/100 with .12 is still .12 since .12 is already rounded to the nearest 100’ths. Instead, use a random Number and round that…

onClipEvent(mouseMove){
x = this._x + Math.round(Math.random()*100)/100;
y = this._y + Math.round(Math.random()*100)/100;
}

and that should do it

… its only a model…

SHH!

Hello?

Isn’t that what I just did, just keepin’ it simple??

Next time I will require a shrubbery!!!

:downloads file:

yes it is…

why are you asking me fumeng? download rynoe’s latest file and your set :slight_smile:

A nice one to go along with the first shrubbery!!!