View Full Version : Record Current Condition
oluc
January 1st, 2010, 02:25 PM
If I have several items that move across the screen but the user can click any of them at any time, how do I record the current position of the item in order to use that data to change the position of the item?
If you need me to explain more pls let me know! :)
Thanks for any input!
cbeech
January 1st, 2010, 03:22 PM
one method would be to use something like this in your event handler:
var position:Object = new Object();
function clickIT(event:MouseEvent):void {
position.x = event.target.x;
position.y = event.target.y;
}
the above will 'record' the coordinates of the instance clicked, BUT will change on every click of any listener assigned to the handler. if you want to keep data for 'each' element - then you could create a new Object instance and store them in an array - it will depend on 'what' you want to use the data for and 'when' you want to use it.
oluc
January 2nd, 2010, 10:09 PM
Thankyou. This is what I am doing: I have 11 images that slide accross the screen. The user can click any of them at any time. When he clicks one I am scaling the image so it looks like it is comming forward and then the rest of the images are scaled down so it looks like they are going back on z axis. So what I am trying to do is record the current position of the image when the user clicks it so that I can use that to correctly estimage the scaling and moving of the image to make it look like it scales from the center and not from the top left corner.
So if have a variable that gets the current position of the image being clicked I'm thinking I can change its position using something like: x = currentposition + -45;
kadaj
January 3rd, 2010, 01:04 AM
add a mouse click event to the pictures and get the x and y position of the clicked picture.
xPosition = picture.x;
yPosition = picture.y;
the x and y by default will be the coordinates of the top left origin
cbeech
January 3rd, 2010, 12:05 PM
@oluc - well you 'could' do that, but have you considered changing the registration point to center? then you would simply need to assign a tweens to each instance and would not have to run the calculations - however this is quite possible ;)
here's a quick example of what i *think* you might be going for - i'm sure that the action is not quite dialed in to what you'd like but it might give you some ideas :D
(code found in first frame)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.