A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] Editing a code that draws a line following an object

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    8

    resolved [RESOLVED] Editing a code that draws a line following an object

    Hi. I'm trying to make an Etch-a-Sketch kind of game for fun. I think it's a simple problem, but I tend to type a lot of stuff for some reason. I found this code to build upon:

    ACTIONSCRIPT Code:
    createEmptyMovieClip("Line",1);
    Line.lineStyle(1,0x000000,100);
    onMouseDown = function ()
    {
            Line.moveTo(_xmouse, _ymouse);
            onMouseMove = function ()
            { Line.lineTo(_xmouse, _ymouse);}
    }

    onMouseUp=function()
    {
            onMouseMove=null;
    }

    The code above works perfectly; it draws the line by holding down the mouse key and moving the mouse to draw. However, I want to change it to be keyboard controlled, so I created an invisible dot object that moves around to the arrow keys, and I want the line to continuously draw (as if the mouse button is always being held in the previous code) at the location of the invisible dot, pretty much drawing the path the dot takes.

    I tried changing _xmouse to _root.dotmain._x (that's the name of the invisible dot) and y_mouse to _root.dotmain._y, and the code still worked if I kept on moving the mouse around. That's obviously impractical though lol.

    With that in mind, I'm trying to figure out how to make it so you don't even have to touch the mouse and it will always draw the line. I tried my shabby editing on the code and got this:

    ACTIONSCRIPT Code:
    onKeyDown = function ()
    {
            Line.moveTo(_root.dotmain._x, _root.dotmain._y);
            onKeyDown = function ()
            { Line.lineTo(_root.dotmain._x, _root.dotmain._y);}
    }

    But nothing happens. I've tried modifying the code a whole bunch of different ways but I think I'm at a dead end. Any help would be appreciated!

  2. #2
    Junior Member
    Join Date
    Jul 2010
    Posts
    8
    I found out myself, I just needed to put the lineTo in the onEnterFrame function.

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