A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Drawing Dynamic straight lines

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

    Drawing Dynamic straight lines

    Hey!

    My question is regarding drawing a straight line, just like on the flash game Line rider. I need to be able to create a line by dragging it with the mouse.

    Any help would be appreciated

    Regards

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    Would it be something like:
    PHP Code:
    this.onMouseDown = function()
    {
        var 
    n:Number this.getNextHighestDepth();
        var 
    mc:MovieClip this.createEmptyMovieClip("mc" nn);

        var 
    x0:Number _xmouse;
        var 
    y0:Number _ymouse;


        
    this.onMouseMove = function()
        {
            
    mc.clear();
            
    mc.lineStyle(1);
            
    mc.moveTo(x0,y0);
            
    mc.lineTo(_xmouse,_ymouse);

            
    updateAfterEvent();
        };
    };

    this.onMouseUp = function()
    {
        
    delete this.onMouseMove;
    }; 

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    3
    Hey, thanks so much for your reply!

    It works perfectly on the main timeline in a new flash file, but when I implement it into my project (inside a movieclip on frame 2 - "Activate pen" sort of thing) it draws a line, and when I go to draw another it deletes the previous.

    Is there a way of fixing this?

    Regards

    Andeh

  4. #4
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    I'd say that you have some other code interfering with this one as this should work (on its own) inside any MovieClip, on any frame.
    This is because I used this.getNextHighestDepth(); to create a new MovieClip, which means that the previous one is never removed.

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