0
votes
package  {

import Scripts.Grid

public class Pathfinding {

    private var $xmlLoader:URLLoader = new URLLoader();
    $xmlLoader.addEventListener(Event.COMPLETE, loadXML);
    $xmlLoader.load(new URLRequest("grid.xml"));
    public static var DepStation:String = new String;
    public static var ArrStation:String = new String;

    public function Pathfinding() {
        // constructor code
    }
    public function loadXML(e:Event):void
    {
        var $xml:XML = new XML(e.target.data);

        var $grid:Grid = new Grid();
        $grid.parseXML($xml);
        trace($grid.findPath(DepStation, ArrStation));
    }

}

}

Hi, my problem here is that Flash will output an error

Line 16 1046: Type was not found or was not a compile-time constant: Event.

and when I tried import Flash.events.Event, the errors will explode and produce

Line 9 1120: Access of undefined property $xmlLoader.

Line 9 1120: Access of undefined property loadXML.

Line 10 1120: Access of undefined property $xmlLoader.

Line 10 1180: Call to a possibly undefined method URLRequest.

Line 8 1046: Type was not found or was not a compile-time constant: URLLoader.

Line 8 1180: Call to a possibly undefined method URLLoader.

Line 8 1180: Call to a possibly undefined method URLLoader.

so I'm really at the end of my wits, the source for the script was http://lassieadventurestudio.wordpress.com/2008/12/09/a-star-pathfinding/ it was working before if I copied it 1:1 but now even the 1:1 clone is not working and the adaption to external actionscripts are not working.

Much help is appreciated

1
To start with, you're missing some imports, like import flash.events.*. And you can't write code at the class level, outside of a method -- only variable declarations (with initialization).Cameron

1 Answers

1
votes

This is how it should work

package  {

import Scripts.Grid;
import flash.events.Event;

public class Pathfinding {

private var $xmlLoader:URLLoader;
public static var DepStation:String = new String();
public static var ArrStation:String = new String();

public function Pathfinding() {
    // constructor code
     $xmlLoader = new URLLoader();
     $xmlLoader.addEventListener(Event.COMPLETE, loadXML);
     $xmlLoader.load(new URLRequest("grid.xml"));
}
public function loadXML(e:Event):void
{
    var $xml:XML = new XML(e.target.data);

    var $grid:Grid = new Grid();
    $grid.parseXML($xml);
    trace($grid.findPath(DepStation, ArrStation));
}

}

So you had a couple of issues,

1) if you create a String Object by doing "new String()" you need to include the (), just like every other Object you create.

2) You need to import all the stuff you are going to use, i.e. the Event class from flash

3) You cannot use methods or similar on the class level, which means methods like "addEventListener(...)" or "load(...)" should be either in the constructor, or in another method.

Why did they write it like that in the tutorial then, you might ask. Well, in the tutorial the guy explicitly says to put it this code in your timeline (in Flash PRO, that is). Timeline coding and Object-Oriented coding are very different in the way you write them.