Advanced drawing, XML and math question

Hello all. SOme of the veterans on here helped me out with part of this continuing development, but I need to dip into your brains again.

I have XML data that looks like this:

197,168,198,168,204,168,206,168,207,169,208,etc

This stuff is XY coordinate pairs, X1, Y1, X2, Y2, X3, Y3, etc. and are used by a drawing function to trace out a particular freeform shape. This works fine, thanks to you guys. This array of data is usually 200-400 items long.

Here is the AS code that is handling the reading of the XML and the drawing of the shape. This all works wonderfully:

this.onMouseUp = function() {
display = mousePos;
//this creates the movie clip for the expert and imports from XML
mc = this.createEmptyMovieClip(“build”, 1);
mc.lineStyle(4, 0xFF0000, 100);
_root.expertArray = new Array();
expertXML = new XML();
expertXML.ignoreWhite = true;
expertXML.load(fileExp);
expertXML.onLoad = function() {
if (_root.drawOK == “yes”) {
for (var i = 0; i<this.firstChild.childNodes.length; i++) {
_root.expertArray* = this.firstChild.childNodes*.firstChild.nodeValue.split(",");
mc.moveTo(_root.expertArray*[0], _root.expertArray*[1]);
//
for (var j = 2; j<_root.expertArray*.length; j += 2) {
mc.lineTo(_root.expertArray*[j], _root.expertArray*[j+1]);
}
//settign variables for the array values and positions
origXexp = _root.expertArray*[0];
origYexp = _root.expertArray*[1];
lastXpos = _root.expertArray*.length-2;
lastYpos = _root.expertArray*.length-1;
lastXexp = _root.expertArray*[lastXpos];
lastYexp = _root.expertArray*[lastYpos];
}
}
};
this.onEnterFrame = null;
};

I am looking at the array and grabbing some points out, namely the first and last XY pairs, which I need for something else. That’s the origXexp, origYexp stuff.

The real problem is that I need to run a mathematical calculation on the data in this array. While this is a little hard to explain, I need to create a variable, let’s call it expert_area, and then sequentially rip through that long string of numbers and do the following math (I’ll use the simple X1 Y1 example):

expert_area=0
expert_area = expert_area+((X1Y2 - X2Y1)/2)

where we move through the long string a pair at a time. So the first calculation would be (X1Y2 - X2Y1), the next would be (X2Y3 - X3Y2), (X3Y4 - X4Y3), etc.

I’ve tried building loops to get the length of the expertArray* and then using that as the basis to proceed through the data. But everything I try either produces no results, or gets Flash stuck in an infinite loop. I’m unsure of where to put this, and how to construct it.

I need some help guys! I feel like it’s close, but I’ve hit a wall on this one.