Skip to main content
Participant
February 24, 2012
Question

Connecting Dots.

  • February 24, 2012
  • 1 reply
  • 525 views

Hello Everyone!!

Whats the best thing to do when you want to do an animation of a line that connects in each other as you click the button??

you set the dots in a stage, and when you click the button there will be a line that will connect from dot1, into dot2 and so on.. ofcorse it includes animation effect..

line.graphics.moveTo()

i guess is the right thing to do??

any idea?

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
February 24, 2012

you can use animateLineTo():

function animateLineToF(sp:Sprite,x1:int,y1:int,x2:int,y2:int):void{

    var a:Array = paramsF(x1,y1,x2,y2);

    var m:Number= a[0];

    var b:Number = a[1];

   

    with(sp.graphics){

        lineStyle(1,0xff0000);

        moveTo(x1,y1);

    }

    loopCount=0;

    clearInterval(lineToI);

    lineToI = setInterval(lineToF,30,sp,m,b,x1,x2);

}

function lineToF(sp:Sprite,m:Number,b:Number,x1:int,x2:int):void{

    var inc:int = speed*(-x1+x2)/Math.abs(x1-x2);

    loopCount++;

    if((inc>0&&loopCount*speed+x1<x2) || (inc<0&&-loopCount*speed+x1>x2)){

    with(sp.graphics){

        lineTo(loopCount*inc+x1,m*(x1+loopCount*inc)+b);

    }

    } else {

        clearInterval(lineToI);

    }

}

function paramsF(x1:int,y1:int,x2:int,y2:int):Array{

    var m:Number = (y1-y2)/(x1-x2);

    var b:Number = y1-m*x1;

    return [m,b];

}

jeponkzAuthor
Participant
February 24, 2012

hello kglad.

did you make that functions?? uhmm..

I can't understand the codes, maybe it is an advance one.. I`m just a begginner one,

i`ll try to understand it kglad. can you make help me?? just give some comments on every function please??