PDA

View Full Version : Change xy position of an object using buttons



MK74
May 9th, 2009, 10:49 PM
Hello all! I started using Flash again after a "brief" hiatus (the last time I used it, Flash was on it's MX version :puzzle:)
See, I am trying to create an animation in which I can move across the stage a simple object (a circle, a square or a star, for example) using buttons (left, right, up and down)
This was fairly simple using AS 1, even when I was no expert. The thing is that those simple ways are no longer working with AS 3.
I spent a few hours doing some research until I found this nice tutorial on this same site:

http://www.kirupa.com/developer/actionscript/xymove.htm
I followed the tutorial, and all was working nicely, but when I attempted to do the animation from scratch, it simply didn't work ;(
I even used the same names for all the objects and instances, but still nothiing. I know that this tutorial uses AS 1, I'd just like to find a way to do it in AS 3 (or maybe AS 2)
I'm open to sugestions :p

Thank you all in advance.

Cheers!
MK74

_forumSteve
May 11th, 2009, 05:17 PM
I'd highly recommend the following article if you're transitioning to AS3.

http://www.adobe.com/devnet/actionscript/articles/event_handling_as3.html (http://www.adobe.com/devnet/actionscript/articles/event_handling_as3.html)

As for the code...

button.addEventListener( MouseEvent.CLICK, handleMouseEvent );

function handleMouseEvent( e:MouseEvent ) {
theObject.x += 5;
}