Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6757239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:37:21+00:00 2026-05-26T13:37:21+00:00

I am trying to create to movable instances, that are draggable, and which have

  • 0

I am trying to create to movable instances, that are draggable, and which have a line connecting them which updates automatically.

The thing is: The original line just goes randomly and doesn’t update as the instances (mc1, mc2) are being dragged.
Here is the code I have got so far:

 mc1.addEventListener(MouseEvent.MOUSE_DOWN, function (e:MouseEvent):void
{
    e.currentTarget.startDrag();
});

mc1.addEventListener(MouseEvent.MOUSE_UP, function (e:MouseEvent):void
{
    e.currentTarget.stopDrag();
});
mc2.addEventListener(MouseEvent.MOUSE_DOWN, function (e:MouseEvent):void
{
    e.currentTarget.startDrag();
});

mc2.addEventListener(MouseEvent.MOUSE_UP, function (e:MouseEvent):void
{
    e.currentTarget.stopDrag();
});

var mc:MovieClip = new MovieClip();
mc.graphics.beginFill(0x000000);
mc.graphics.lineStyle(2,0x000000);

//start drawing the line
mc.graphics.moveTo(mc1.x,mc1.y);
mc.graphics.lineTo(mc2.x,mc2.y);
mc.graphics.endFill();

//Position your new movie clip
addChild(mc);

Can anyone tell me where have I got it wrong?

Thanks a lot of any help !!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:37:22+00:00Added an answer on May 26, 2026 at 1:37 pm

    What you need to do is capture the movement of the users mouse as (s)he is dragging the MovieClip.

    First create a isDragging variable var isDragging:Boolean = false; and set this to true when mouse down and false when mouse up.

    Then add a MouseEvent.MOUSE_MOVE event listener to the line timeline

    addEventListener(MouseEvent.MOUSE_MOVE, function (e:MouseEvent):void
    {
        if (isDragging) {
            drawConnectiveLine(mc1, mc2);
        }
        return;
    });
    

    The method drawConnectiveLine will update the line vector shape to move to {x, y} of the movieclips.

    function drawConnectiveLine(d:DisplayObject, d2:DisplayObject):void {
        mc.graphics.clear();
        mc.graphics.lineStyle(2,0);
        mc.graphics.moveTo(d.x,d.y);
        mc.graphics.lineTo(d2.x,d2.y);
    }
    

    Modifications to your pre-existing script:

    var isDragging:Boolean = false;
    var mc:MovieClip = new MovieClip();
    mc.graphics.lineStyle(2,0);
    mc.graphics.moveTo(mc1.x,mc1.y);
    mc.graphics.lineTo(mc2.x,mc2.y);
    addChild(mc);
    
    mc1.addEventListener(MouseEvent.MOUSE_DOWN, function (e:MouseEvent):void
    {
        isDragging = true;
        e.currentTarget.startDrag();
    });
    
    mc1.addEventListener(MouseEvent.MOUSE_UP, function (e:MouseEvent):void
    {
        isDragging = false;
        e.currentTarget.stopDrag();
    });
    
    mc2.addEventListener(MouseEvent.MOUSE_DOWN, function (e:MouseEvent):void
    {
        isDragging = true;
        e.currentTarget.startDrag();
    });
    mc2.addEventListener(MouseEvent.MOUSE_UP, function (e:MouseEvent):void
    {
        isDragging = false;
        e.currentTarget.stopDrag();
    });
    addEventListener(MouseEvent.MOUSE_MOVE, function (e:MouseEvent):void
    {
        if (isDragging) {
            mc.graphics.clear();
            mc.graphics.lineStyle(2,0);
            mc.graphics.moveTo(mc1.x,mc1.y);
            mc.graphics.lineTo(mc2.x,mc2.y);
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying create a data.frame from which to create a graph. I have
I am trying create a trending system that displays which keywords are trending by
I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create my first iPhone app that would play back audio. When I
Trying to create a small monitor application that displays current internet usage as percentage
I'm trying create a box in my Django app that displays text (and possibly
I'm trying create a ASMX webservice that can perform a HTTP GET request. I
I'm trying to write a table trigger which queries another table that is outside
Trying to create a simple plugin that simply connects to an ftp site, looks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.