A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Displaying mouse X/Y coordinates dynamically

  1. #1

    Talking


    I can't seem to find any of the sample movies that demonstrate this. I want to have text boxes that dynamically display the cursor's X and Y coordinates/positions in the clip. Any suggestions?

    Umnbrella

  2. #2
    deva_station
    Guest
    draw a dynamic text box on your main stage with varialbe name out

    add the following code to a dummy MC:
    Code:
    onClipEvent(enterFrame){
    _root.out="X:"+_root._xmouse+" "+"Y:"+root._ymouse;
    }

  3. #3
    Junior Member
    Join Date
    Nov 2001
    Posts
    21
    Hmm if i understand your question correctly you just need to create two text boxes call one xpos and the other ypos then

    onClipEvent (enterFrame) {
    xpos = _root._xmouse
    ypos = _root._ymouse
    }

    i've included a link to the sample let me know if this is what you were looking for

    http://www.floppyfish.net/flash/coord.swf

    Regards
    Darren

  4. #4

    Talking


    So far I understand all of the logic behind what you all are suggesting (thank you, by the way), however I'm stuck on the 'onClipEvent' aspect of it. I can't seem to get the 'onClipEvent' to work without errors. Could someone kinda walk me through the steps of the dummy MC and where the code goes?

    Thanks again!
    Umnbrella

  5. #5

    Nevermind..I just realized that the events have to be attached to the clips instead of objects or frames.

    Thanks!
    Umnbrella

  6. #6
    Junior Member
    Join Date
    Nov 2001
    Posts
    21
    Originally posted by Umnbrella

    So far I understand all of the logic behind what you all are suggesting (thank you, by the way), however I'm stuck on the 'onClipEvent' aspect of it. I can't seem to get the 'onClipEvent' to work without errors. Could someone kinda walk me through the steps of the dummy MC and where the code goes?

    Thanks again!
    Umnbrella
    Ok here we go i'll step you through a text box for the x-coord. and you should ba able to do the y part the same.

    1 Start new flash file
    2 insert -> new symbol call it coords and make it a movie clip
    3 now inside the movie clip make a text box. make it dynamic single line and variable name xpos. re size it so it will fit enough digits set font and colour to what ever you want.

    4 go back to the main movie and insert the clip from the library.

    5 make sure its selected and open the actions window.

    add code

    onClipEvent (enterFrame) {
    xpos =_root._xmouse
    }

    or and of the above examples.

    6 Ctrl + Enter to test

    all done.





  7. #7
    Junior Member
    Join Date
    Feb 2008
    Posts
    1

    Here is how to do that...

    Start a new flash project by going to File > New (or pressing Ctrl+N);

    Open the actions panel by hitting F9;

    Enter the following code:

    stop();
    _root.onEnterFrame = function() {
    trace('mouse-x: ' + _root._xmouse + newline + 'mouse-y: ' + _root._ymouse);
    }

    -- End code --

    Now test your movie by hitting Ctrl+Enter;

    Enjoy the silence

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