hey ppl,

i've been attempting some pathfinding and i have gotten really close! it works fine untill its surrounded by other nodes that have already been tested which means it cant do complex maps so heres the code:

A*
Code:
    package {

       import flash.display.*;
       import flash.events.*;
       import flash.utils.*;
       import flash.text.TextField;

       public class pf extends MovieClip {

          public var map:Array = new Array();
          public var floor:int=0;
          public var wall:int=1;

          public var tileWidth:Number=20;

          public var xcoord;
          public var ycoord;
          public var curX;
          public var curY;
          public var startX;
          public var startY;
          public var endX;
          public var endY;
          public var startNode;
          public var endNode;
          public var Hx:Number;
          public var newGx:Number;
          public var nextNode;
          public var openSet:Array = new Array();
          public var closedSet:Array = new Array();

          public var nodeAr:Array  = new Array();

          public var dontPush:Boolean = false;

          public var mLength:Number;

          public var fAr:Array = new Array();


          public var startDown:Boolean=false;
          public var openSetChange:Boolean=false

          public var startPos:startBlock=new startBlock;
          public var endPos:endBlock=new endBlock;
          public var highlighter:squareSelected=new squareSelected;

          public function initPF() {
             map = [
             /*[1,1,1,1,1,1,1],
              [1,0,0,0,0,0,1],
              [1,0,0,0,0,0,1],
              [1,0,1,1,1,1,1],
              [1,0,0,0,0,0,1],
              [1,0,0,0,0,0,1],
              [1,1,1,1,1,1,1]
              ];*/

              [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
              [1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1],
              [1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1],
              [1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0,0,1],
              [1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,0,1],
              [1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1],
              [1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1],
              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,1],
              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,0,1],
              [1,0,1,0,0,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1],
              [1,0,1,0,0,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,1,1,0,1,0,1],
              [1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1],
              [1,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,0,1,0,1,0,0,0,1,0,1],
              [1,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,1,1,1,1,1,0,1],
              [1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1],
              [1,0,1,0,0,0,1,0,1,0,1,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1],
              [1,0,1,0,0,0,1,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1],
              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1],
              [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
              ];

             mLength = map[0].length;
             //trace("mlength: "+mLength)

             addChild(endPos);
             addChild(startPos);
             addChild(highlighter);

             addEventListener(Event.ENTER_FRAME,calcMousePos);
             addEventListener(MouseEvent.CLICK,startFinInit);


             for (var k in map[0]) {
                for (var i in map[k]) {
                   var n:node = new node(i,k,map[k][i]);
                   addChildAt(n,0);
                   if (nodeAr.length>=1) {

                      nodeAr.push(n);

                   } else {
                      nodeAr.push(n);
                   }
                }
             }

             var button:path = new path();
             addChild(button);
             button.addEventListener(MouseEvent.CLICK,nextStep);


          }
          public function nextStep(event:MouseEvent) {
             contAstar(nextNode,nextNode.x,nextNode.y,endNode.x,endNode.y);
          }

          public function calcMousePos(event:Event) {
             xcoord=Math.floor(mouseX/tileWidth);
             ycoord=Math.floor(mouseY/tileWidth);
             highlighter.x=xcoord*tileWidth;
             highlighter.y=ycoord*tileWidth;
             //trace(mLength*ycoord+xcoord)
          }


          public function startFinInit(event:MouseEvent) {
             //trace(nodeAr[0]);
             if (startDown==false) {
                if (map[ycoord][xcoord]!=wall) {
                   startPos.x=highlighter.x;
                   startPos.y=highlighter.y;
                   startNode = nodeAr[mLength*ycoord+xcoord];
                   trace(startNode.x,nodeAr[mLength*ycoord+xcoord])
                   startDown=true;
                }
             } else {
                if (map[ycoord][xcoord]!=wall) {
                   endPos.x=highlighter.x;
                   endPos.y=highlighter.y;
                   endNode = nodeAr[mLength*ycoord+xcoord];
                   firstCalc(startNode,startNode.x,startNode.y,endNode.x,endNode.y);
                   startDown=false;
                   trace(startNode.x,startNode.y,endNode.x,endNode.y);

                }
             }
          }
          public function contAstar(sNode,cx,cy,ex,ey) {
             if (sNode!= endNode) {
                if (openSet.length>0) {
                   SurroundCalc(sNode,cx,cy-tileWidth,ex,ey);
                   SurroundCalc(sNode,cx,cy+tileWidth,ex,ey);
                   SurroundCalc(sNode,cx-tileWidth,cy,ex,ey);
                   SurroundCalc(sNode,cx+tileWidth,cy,ex,ey);
                   getSmallestF();
                   getNextNode();
                }
             } else {
                trace("pathFound");
             }
          }
          public function firstCalc(sNode,cx,cy,ex,ey) {
             trace(cx,cy,ex,ey);
             trace("iName = "+sNode.iName);
             sNode.g = 0;
             sNode.h = hueristic(cx,cy,ex,ey);
             sNode.f = sNode.g+sNode.h;
             closedSet.push(sNode);
             SurroundCalc(sNode,cx,cy-tileWidth,ex,ey);
             SurroundCalc(sNode,cx,cy+tileWidth,ex,ey);
             SurroundCalc(sNode,cx-tileWidth,cy,ex,ey);
             SurroundCalc(sNode,cx+tileWidth,cy,ex,ey);
             getSmallestF();
             getNextNode();
          }
          public function hueristic(x1,y1,x2,y2) {
             Hx = Math.sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));
             Hx = Math.round(Hx);
             return Hx;
          }
          public function SurroundCalc(pNode,cx,cy,ex,ey) {
             dontPush = false;
             openSetChange = false

             for (var i:Number = 0; i<=nodeAr.length-1; i++) {


                if (nodeAr[i].x == cx && nodeAr[i].y == cy) {


                   for (var k:Number = 0; k <openSet.length; k++) {
                      if (openSet[k].iName == nodeAr[i].iName) {
                         openSetChange = true
                         trace("in open set");
                         trace("node: "+nodeAr[i].iName+" , "+"open: "+openSet[k].iName+"\n");
                      }
                   }
                   for (var j:Number = 0; j <closedSet.length; j++) {
                      if (closedSet[j].iName  == nodeAr[i].iName ) {
                         dontPush = true;
                         trace("in closed set");
                         trace("node: "+nodeAr[i].iName+" , "+"closed: "+closedSet[j].iName+"\n");
                      }
                   }
                   if (dontPush  == false) {
                      //trace(nodeAr[i].notWalkable)
                      if(!openSetChange){
                         if (nodeAr[i].notWalkable == false) {
                            pNode = MovieClip(parent).nodeAr[i];
                            var sNode = nodeAr[i];
                            sNode.g = pNode.g+10;
                            sNode.h = hueristic(cx,cy,ex,ey);
                            sNode.f =sNode.g+ sNode.h;
                            //trace("F: "+nodeAr[i].f);
                            openSet.push(sNode);
                            //trace("openSet.length: "+openSet.length)
                            for (var l:Number = 0; l < fAr.length; l++) {
                               fAr.splice(0,1);
                            }
                         }
                      }else{
                         sNode = nodeAr[i];
                         newGx = pNode.g+10;
                         if(newGx<sNode.g){
                            sNode.g = newGx;
                            sNode.f =sNode.g+ sNode.h;
                         }
                      }
                               
                   }
                }
             }
             trace("");
          }
          public function getSmallestF() {
             
             for (var i:Number = 0; i<=openSet.length-1; i++) {
                //trace(openSet[i].f)
                fAr.push(openSet[i].f);
                //trace("pushed")
             }
             fAr.sort(Array.NUMERIC);
             trace("far: "+fAr)
          }
          
          public function getNextNode() {
             closedSetPush:
             for (var i:Number = 0; i<=nodeAr.length; i++) {
                for (var k:Number = 0; k<=openSet.length-1; k++) {
                   //trace(openSet[k].iName+" is in openSet")
                   if (openSet[k].iName == nodeAr[i].iName) {
                      if (nodeAr[i].f == fAr[0]) {
                         trace("moved "+openSet[k].iName+" to closedSet");
                         closedSet.push(nodeAr[i]);
                         openSet.splice(k,1);
                         nextNode = nodeAr[i];
                         break closedSetPush;
                      }
                   }
                   /*wpx.push(nextNode.x)
                   wpy.push(nextNode.y)*/
                   
                }
             }
             for (var l:Number = 0; l<=closedSet.length-1; l++) {
                      trace(closedSet[l].iName+" is in closedSet")
             }
          }
       }
    }
node:
Code:
    package {

       import flash.display.*;
       import flash.events.*;
       import flash.utils.*;
       import flash.text.TextField;

       public class node extends MovieClip {
          public var f:Number = -1;
          public var g:Number = -1;
          public var h:Number = -1;
          public var notWalkable:Boolean = true;
          public var costMultiplier:Number=1.0;

          /*this.instanceName = "node"+(i*K)
          trace(this.instanceName)*/

          public function node(x,y,nw) {
             addEventListener(Event.ENTER_FRAME,upDate);
             if (nw == false) {
                this.h_TXT.text = "";
                this.g_TXT.text = "";
                this.f_TXT.text = "";
                this.gotoAndPlay(1);
             } else {
                this.gotoAndPlay(2);
             }
             notWalkable = nw
             this.x=x*40;
             this.y=y*40;

          }
          public function upDate(event:Event) {
             if (notWalkable == false) {
                if (h>=0) {
                   this.h_TXT.text = h.toString();
                }
                if (g>=0) {
                   this.g_TXT.text = g.toString();
                }
                if (f>=0) {
                   this.f_TXT.text = f.toString();
                }
             }
          }
       }
    }
(excuse all the traces)

is there something i have done wrong? cos i'm sure i have got it 99% right just that last bit is wrong cheers to the person that helps me!