A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [MX] Drag & Drop with drawLine

Threaded View

  1. #1
    Member
    Join Date
    Dec 2008
    Posts
    50

    [MX] Drag & Drop with drawLine

    Hi,

    I am creating a drag and drop where the user drags an object to the target and in doing so they create a line between where the object started and the target.

    I have got this working fine for one set of objects, however, if there are three on the screen the drawline function only works for the first one, the others do not draw a line.

    Is there a method I should be using so that I can have multiple objects and targets with lines drawn between them?

    Code is here :

    PHP Code:
    // code for UK
    _root.createEmptyMovieClip("line_mc"1);

    onMouseMove = function(){
    updateAfterEvent();


    MovieClip.prototype.drawLine = function()
        {
        
    this.clear();
        
    this.lineStyle(2,0xFF9900,100);
        
    this.moveTo(mc1._xmc1._y);
        
    this.lineTo(mc2._xmc2._y);
        
    this.this._x;
        
    this.this._y;
        }

        
    // ensure movieclips are in front of line
        
    mc1.swapDepths(2);
        
    mc2.swapDepths(3);

        
    // draw initial line
        
    line_mc.drawLine();

    mc2.onPress = function()
        {
        
    this.startDrag();
        
    line_mc.onEnterFrame drawLine;
        }

    mc2.onRelease = function()
        {
        
    delete line_mc.onEnterFrame;
        
    this.stopDrag();
        
    checkTarget(this);
        if (eval(
    this._droptarget) == uktarget) {
        
    this._x uktarget._x;
        
    this._y uktarget._y;
        } else if (eval(
    this._droptarget) == francetarget) {
        
    this._x francetarget._x;
        
    this._y francetarget._y;
        }else if (eval(
    this._droptarget) == germantarget) {
        
    this._x germantarget._x;
        
    this._y germantarget._y;
        } else {
        
    this._x this.x;
        
    this._y this.y;
        }
    }
    function 
    checkTarget(drag){
    // trace(drag+ "has been dropped on "+eval(drag._droptarget));
    if (drag.hitTest(uktarget)) {
    trace(drag+" has been dropped on greyCircle");
    } else {
    trace("you missed the target");
    }

    Last edited by wakey; 01-20-2009 at 04:14 AM.

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