-
AS3 startDrag x y coordinates
Hey guys, not sure if this is possible but i'd like to get the X,Y coordinates of a button I drag. here's my problem:
PHP Code:
public function backbuttonDown(e:MouseEvent)
{
backbutton_btn.startDrag();
}
public function backbuttonMove(e:MouseEvent)
{
trace(backbutton_btn.x +","+backbutton_btn.y);
}
the x and y coordinates remain the same even though i'm clearly dragging my button all over the stage. I did code my own by putting events and whatnot around the button but startDrag seemed smoother and faster. is it even possible?
-
AKA [ Paul Bainbridge]
Maybe this should be posted here
-
trace("AKA: Biro Barna");
Try something like this:
PHP Code:
box.addEventListener(MouseEvent.MOUSE_DOWN, onDown); box.addEventListener(MouseEvent.MOUSE_UP, onUp);
function onDown(event:MouseEvent):void { box.addEventListener(Event.ENTER_FRAME, onEnter); box.startDrag(); }
function onUp(event:MouseEvent):void { box.removeEventListener(Event.ENTER_FRAME, onEnter); box.stopDrag(); }
function onEnter(event:Event):void { trace(box.x + " " + box.y); }
| Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro | WebLog: http://blog.wisebisoft.com/ |
| Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
| Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/ | By perseverance the snail reached the ark. |
-
Originally Posted by PlenaryCreation
Try something like this:
PHP Code:
box.addEventListener(MouseEvent.MOUSE_DOWN, onDown); box.addEventListener(MouseEvent.MOUSE_UP, onUp);
function onDown(event:MouseEvent):void { box.addEventListener(Event.ENTER_FRAME, onEnter); box.startDrag(); }
function onUp(event:MouseEvent):void { box.removeEventListener(Event.ENTER_FRAME, onEnter); box.stopDrag(); }
function onEnter(event:Event):void { trace(box.x + " " + box.y); }
nope, i'm still yielding "0 0" in the console. Does it normally not behave like this?
-
trace("AKA: Biro Barna");
^ I tested that code before posting it, and it's a 100% working code.
If it didn't work for your then obviously you are doing something wrong.
Try again.
| Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro | WebLog: http://blog.wisebisoft.com/ |
| Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
| Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/ | By perseverance the snail reached the ark. |
-
Originally Posted by PlenaryCreation
^ I tested that code before posting it, and it's a 100% working code.
If it didn't work for your then obviously you are doing something wrong.
Try again.
Alright, I tested it again and nothing. I'll tell you what I did:
Create new flash 3.0 file, create new actionscript file called test.as. From here I linked in the document class to be this test.as file. I also included the Button component into the library so I can see it. in the test.as file is the following code, please try these steps and tell me if it works for you.
PHP Code:
package { import flash.events.*; import fl.controls.*; import flash.display.*;
public class test extends MovieClip {
public function test() { var box:Button = new Button();
box.addEventListener(MouseEvent.MOUSE_DOWN, onDown); box.addEventListener(MouseEvent.MOUSE_UP, onUp); box.label = "myBox";
addChild(box);
function onDown(event:MouseEvent):void { box.addEventListener(Event.ENTER_FRAME, onEnter); box.startDrag(); }
function onUp(event:MouseEvent):void { box.removeEventListener(Event.ENTER_FRAME, onEnter); box.stopDrag(); }
function onEnter(event:Event):void { trace(box.x + " " + box.y); } } } }
-
trace("AKA: Biro Barna");
PHP Code:
package { import flash.events.*; import flash.display.*;
public class test extends MovieClip {
public function test() { var box:BoxMC = new BoxMC(); addChild(box); box.addEventListener(MouseEvent.MOUSE_DOWN, onDown); box.addEventListener(MouseEvent.MOUSE_UP, onUp);
function onDown(event:MouseEvent):void { box.addEventListener(Event.ENTER_FRAME, onEnter); box.startDrag(); }
function onUp(event:MouseEvent):void { box.removeEventListener(Event.ENTER_FRAME, onEnter); box.stopDrag(); }
function onEnter(event:Event):void { trace(box.x + " " + box.y); } } } }
Assuming your movie clip has a linkage name of "BoxMC",
the upper code will work just fine.
| Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro | WebLog: http://blog.wisebisoft.com/ |
| Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
| Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/ | By perseverance the snail reached the ark. |
-
k, you are right about the movie clip, that works great. but try a fl.controls.Button. Tried Simplebutton but unfortunately there's no drag on that guy. maybe it's just a flaw in the actionscript code?
-
trace("AKA: Biro Barna");
^ You can't do that with button symbols. Button symbols are primitive and were design to do things fast... if you are planing on complex stuff in the future, then try not to use button symbols ever again... your best friend is the Movie Clip, stick to it.
| Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro | WebLog: http://blog.wisebisoft.com/ |
| Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
| Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/ | By perseverance the snail reached the ark. |
-
associated query
Hi, I have a query similar to one that you have and someone kindly solved for you.
I'm trying to create a stickman that can be manipulated by the user into various positions, save the positions on the timeline and the user should be able to pay back the sequence of movements.
I figure I need to get the xy coordinates somehow and enter them in an array or something like that but have no idea where to begin....
any help on how i can achieve this is very much appreciated.
-
obj.startDrag(true);
this.addEventListener(Event.ENTER_FRAME, frame);
function frame(e:Event){
trace(obj.x + "," + obj.y);
}
This is working
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|