Hi
in a nut shell I have found this wicked piece of open source actionscript.
It responds to the cursor and was wondering if it is posible to modify the x_position and y_position actions and make the action respond to a moving object??? (a movieclip with a variable name)
is this to complicated to attempt or is it doable??
THANKS FOR ANY COMMENTS
ACTIONSCRIPT
//
var rows, colm:Number;
//
function setQuality(thisSpeed:Number):Void {
if (thisSpeed == 1) {
rows = 9;
colm = 18;
} else if (thisSpeed == 2) {
rows = 13;
colm = 22;
} else {
rows = 17;
colm = 28;
}
}
setQuality(_global.speed);
//
// p = point :: t = target :: d = distance :: c = constant :: v = velocity :: f = friction
function flex(p:Number, t:Number, d:Number, c:Number, v:Number, f:Number):Object {
var obj:Object = {d:(((t-p)/c)*v)+(d*f), p:p+d};
return (obj);
}
//
function createBackground():Void {
// start depth
var dep:Number = 1;
// create a background
this.createEmptyMovieClip("bk", dep++);
var bk:MovieClip = this["bk"];
var colors:Array = [0x297396, 0x0B1F28];
var alphas:Array = [100, 100];
var ratios:Array = [0, 255];
var matrix:Object = {matrixType:"box", x:left, y:top-90, w:right-left, h:bottom-top, r:Math.PI/2};
bk.beginGradientFill("linear", colors, alphas, ratios, matrix);
bk.moveTo(left, top);
bk.lineTo(right, top);
bk.lineTo(right, bottom);
bk.lineTo(left, bottom);
bk.lineTo(left, top);
bk.endFill();
// create mask for background
this.createEmptyMovieClip("ele", dep++);
var ele:MovieClip = this["ele"];
this.createEmptyMovieClip("mask", dep++);
var mask:MovieClip = this["mask"];
mask.beginFill(0x000000, 100);
mask.moveTo(left, top);
mask.lineTo(right, top);
mask.lineTo(right, bottom);
mask.lineTo(left, bottom);
mask.lineTo(left, top);
mask.endFill();
ele.setMask(mask);
ele.createEmptyMovieClip("dot", 10000);
}
//
function clearAll():Void {
removeMovieClip("ele");
removeMovieClip("bk");
removeMovieClip("mask");
}
//
function createForce(rws:Number, clms:Number):Void {
createBackground();
var ele:MovieClip = this["ele"];
ele.obj_array = new Array();
var maxn:Number = rws*clms;
var cnt:Number = 0;
// find the distance between the objects
var tween_w:Number = (right-left-100)/clms;
var tween_h:Number = (bottom-top-100)/rws;
// set the starting position for the first object
var start_x:Number = left+(tween_w/2)+50;
var start_y:Number = top+(tween_h/2)+50;
var pos_x:Number = start_x;
var pos_y:Number = start_y;
for (var i:Number = 0; i<rws; i++) {
for (var j:Number = 0; j<clms; j++) {
var obj:Object = {x:pos_x, y:pos_y, baseX:pos_x, baseY:pos_y, speedX:1, speedY:1};
ele.obj_array.push(obj);
/////////////////////////// increment x
pos_x += tween_w;
cnt++;
}
/////////////////////////// increment y
pos_x = start_x;
pos_y += tween_h;
}
///////////////////////////////////////set up force
// motion variables
ele.maxD = 100;
ele.power = 7;
ele.friction = .8;
ele.ratio = .25;
ele.maxD2 = ele.maxD*ele.maxD;
ele.a = ele.power/ele.maxD2;
ele.targx = _xmouse;
ele.targy = _ymouse;
ele.dx = 0;
ele.dy = 0;
////////////////////////////////////// extra forces
ele.onMouseDown = function():Void {
this.power = this.power*3;
this.maxD = this.maxD*1.5;
this.maxD2 = this.maxD*this.maxD;
this.a = this.power/this.maxD2;
};
ele.onMouseUp = function():Void {
this.power = this.power/3;
this.maxD = this.maxD/1.5;
this.maxD2 = this.maxD*this.maxD;
this.a = this.power/this.maxD2;
};
////////////////////////////////////////
ele.onEnterFrame = function():Void {
this.clear();
var objx:Object = flex(this.targx, _xmouse, this.dx, 9, 0.8, 0.85);
this.targx = objx.p;
this.dx = objx.d;
var objy:Object = flex(this.targy, _ymouse, this.dy, 12, 0.8, 0.85);
this.targy = objy.p;
this.dy = objy.d;
// force field
for (var i:Number = 0; i<maxn; i++) {
var obj:MovieClip = this.obj_array*;
var disX:Number = this.targx-obj.x;
var disY:Number = this.targy-obj.y;
if (disX>0) {
var signX:Number = -1;
} else {
var signX:Number = 1;
}
if (disY>0) {
var signY:Number = -1;
} else {
var signY:Number = 1;
}
var forceX:Number = 0;
var forceY:Number = 0;
var dis:Number = (disX*disX)+(disY*disY);
if (dis<this.maxD2) {
var force:Number = (-1*this.a*dis)+this.power;
forceX = (disX*disX)/dis*signX*force;
forceY = (disY*disY)/dis*signY*force;
}
obj.speedX = (obj.speedX*this.friction)+((obj.baseX-obj.x)*this.ratio)-forceX;
obj.speedY = (obj.speedY*this.friction)+((obj.baseY-obj.y)*this.ratio)-forceY;
var nx:Number = obj.x+obj.speedX;
var ny:Number = obj.y+obj.speedY;
if (nx<left) {
obj.x = left;
} else if (nx>right) {
obj.x = right;
} else {
obj.x = nx;
}
if (ny<top) {
obj.y = top;
} else if (ny>bottom) {
obj.y = bottom;
} else {
obj.y = ny;
}
this.lineStyle(0, 0xCCFFFF, 40);
this.moveTo(obj.baseX, obj.baseY);
this.lineTo(obj.x, obj.y);
}
};
}
//
createForce(rows, colm);
//
stop();