I'm trying to find a good way to use TweenMax and flash's drawing class together, but it always bogs down and crashes the flash player, and I can't really figure out what's going wrong. Really all I want to do is make sure that when two (or more) circles, connected by a line, move, that the line between them follows. This is my code:
import com.greensock.TweenMax;
var sw = stage.stageWidth;
var sh = stage.stageHeight;
var cr = 3; //circle radius
var moveRange = 20;
var circleColor = 0xcccccc;
var numCircles = 2;
var circleArray = [];
var lineCanvas:Sprite = new Sprite();
addChild(lineCanvas);
var lineColor = 0xe9e9e9;
var lineWeight = 1;
function init(){
drawCircle();
}
function drawCircle(){
for (var i = 0; i<numCircles; i++){
var xPos = randomRange(cr, sw-cr);
var yPos = randomRange(cr, sh-cr);
var newCircle:Shape = new Shape();
newCircle.graphics.beginFill(circleColor);
newCircle.graphics.drawCircle(0,0,cr);
newCircle.x = xPos;
newCircle.y = yPos;
newCircle.graphics.endFill();
circleArray.push(newCircle);
addChild(newCircle);
}
drawLine();
}
function drawLine(){
for (var i = 0; i<numCircles-1; i++){
lineCanvas.graphics.clear();
lineCanvas.graphics.lineStyle(lineWeight,lineColor);
lineCanvas.graphics.moveTo(circleArray[i].x,circleArray[i].y);
lineCanvas.graphics.lineTo(circleArray[i+1].x,circleArray[i+1].y);
}
moveCircle();
}
function moveCircle(){
for (var i = 0; i<numCircles; i++){
var curX = circleArray[i].x;
var curY = circleArray[i].y;
var moveX = randomRange(curX-moveRange,curX+moveRange);
var moveY = randomRange(curY-moveRange,curY+moveRange);
//TweenMax.to(circleArray[i],.5, { x: moveX, y: moveY, onUpdate:drawLine });
}
}
function randomRange(minNum:Number, maxNum:Number):Number {
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}
init();
Is there a better way to do this? Should I not be using a tweening library?