A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: AS3 startDrag x y coordinates

Hybrid View

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Posts
    16

    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.+","+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?

  2. #2
    AKA [ Paul Bainbridge] webdreamer's Avatar
    Join Date
    Aug 2001
    Location
    Glasgow, Scotland, UK
    Posts
    3,320
    Maybe this should be posted here
    .: To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Twitter - Linkedin
    bringmadeleinehome.com

  3. #3
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    Try something like this:

    PHP Code:
    box.addEventListener(MouseEvent.MOUSE_DOWNonDown);
    box.addEventListener(MouseEvent.MOUSE_UPonUp);

    function 
    onDown(event:MouseEvent):void
    {
        
    box.addEventListener(Event.ENTER_FRAMEonEnter);
        
    box.startDrag();
    }

    function 
    onUp(event:MouseEvent):void
    {
        
    box.removeEventListener(Event.ENTER_FRAMEonEnter);
        
    box.stopDrag();
    }

    function 
    onEnter(event:Event):void
    {
        
    trace(box." " 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. |


  4. #4
    Junior Member
    Join Date
    Jan 2008
    Posts
    16
    Quote Originally Posted by PlenaryCreation
    Try something like this:

    PHP Code:
    box.addEventListener(MouseEvent.MOUSE_DOWNonDown);
    box.addEventListener(MouseEvent.MOUSE_UPonUp);

    function 
    onDown(event:MouseEvent):void
    {
        
    box.addEventListener(Event.ENTER_FRAMEonEnter);
        
    box.startDrag();
    }

    function 
    onUp(event:MouseEvent):void
    {
        
    box.removeEventListener(Event.ENTER_FRAMEonEnter);
        
    box.stopDrag();
    }

    function 
    onEnter(event:Event):void
    {
        
    trace(box." " box.y);

    nope, i'm still yielding "0 0" in the console. Does it normally not behave like this?

  5. #5
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    ^ 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. |


  6. #6
    Junior Member
    Join Date
    Jan 2008
    Posts
    16
    Quote 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_DOWNonDown);
                
    box.addEventListener(MouseEvent.MOUSE_UPonUp);
                
    box.label "myBox";

                
    addChild(box);

                function 
    onDown(event:MouseEvent):void {
                    
    box.addEventListener(Event.ENTER_FRAMEonEnter);
                    
    box.startDrag();
                }

                function 
    onUp(event:MouseEvent):void {
                    
    box.removeEventListener(Event.ENTER_FRAMEonEnter);
                    
    box.stopDrag();
                }

                function 
    onEnter(event:Event):void {
                    
    trace(box." " box.y);
                }
            }
        }


  7. #7
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    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_DOWNonDown);
                
    box.addEventListener(MouseEvent.MOUSE_UPonUp);

                function 
    onDown(event:MouseEvent):void {
                    
    box.addEventListener(Event.ENTER_FRAMEonEnter);
                    
    box.startDrag();
                }

                function 
    onUp(event:MouseEvent):void {
                    
    box.removeEventListener(Event.ENTER_FRAMEonEnter);
                    
    box.stopDrag();
                }

                function 
    onEnter(event:Event):void {
                    
    trace(box." " 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. |


  8. #8
    Junior Member
    Join Date
    Jan 2008
    Posts
    16
    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?

  9. #9
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    ^ 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. |


  10. #10
    Junior Member
    Join Date
    Feb 2010
    Posts
    3

    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.

  11. #11
    TheFlashMaster
    Join Date
    Aug 2009
    Posts
    28
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center