I was wondering if there was a way to make custom operators in Flash. I’m trying to make a function that will add the x and y coordinates of two vectors.
va=[x1,y1]
vb=[x2,y2]
vc=va+vb=[x1+x2,y1+y2]
function Vector(x, y)
{
this.x = x;
this.y = y;
}
Vector.prototype.plus = function(v2)
{
this.x += v2.x;
this.y += v2.y;
}
var green=0x00CC00;
var black=0x000000;
var thickness=.5;
//Draws a line from vector a to vector b
function DrawLine(va,vb)
{
var Line:MovieClip = this.createEmptyMovieClip("Line",getNextHighestDepth());
Line.lineStyle(thickness,colour,100);
Line.moveTo(va.x,va.y);
Line.lineTo(vb.x,vb.y);
}
var va = new Vector(10,40);
var vb = new Vector(60,60);
var vc = new Vector(60,60);
vc.plus(va); // i would rather be able to use vc=va+vb;
trace("va=("+va.x+","+va.y+")");
trace("vb=("+vb.x+","+vb.y+")");
trace("vc=("+vc.x+","+vc.y+")");
var colour = black;
DrawLine(va,vb);
var colour = green;
DrawLine(vb,vc);
Once I figure this out I’ll make a vector manipulation class and I can continue with my work.
Any help would be much appreciated!