Im trying to alter the source code that was given to me on the Haxeforums. I wanted the constructor to allow parameters:
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.Sprite;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.events.Event;
import flash.net.URLRequest;
class Tiles extends Sprite
{
static var loader = new Loader();
public static function load () {
loader.load(new URLRequest("tiles.png"));
}
public function new(tilex:Int,tiley:Int)
{
super();
var content:Bitmap = cast(loader.content, Bitmap);
var source:BitmapData = content.bitmapData;
var sourceRect = new Rectangle(20,0,20,20);
var destPoint = new Point(0,0);
var bmd = new BitmapData(20,20);
bmd.copyPixels(source, sourceRect, destPoint);
var bmp = new Bitmap(bmd);
bmp.y = tilex;
bmp.x = tiley;
addChild(bmp);
}
public static function main()
{
load();
var Tile = new Tiles(320, 0);
flash.Lib.current.addChild(Tile);
}
}
And when I compile it, it gives no errors. Yet when I view the flash window, the tile hasn't been added. Can anyone locate the error I've made? I've checked multiple that the "tiles" image is in the correct directory.