HaxePunk is throwing a run-time error when Loading an image

299 views Asked by At

**

SOLVED

**

I am currently making a game in Haxe with the HaxePunk Library which uses OpenFL targeting flash using the Flash Develop IDE. I am following this tutorial.

I have got a class that inherits from Entity:

package ;

import com.haxepunk.Entity;
import com.haxepunk.graphics.Image;

    class Head extends Entity
    {

        public function new(x: Int , y:Int)
        {
            super(x, y);

            graphic = new Image("../assets/gfx/mah.png");
        }

        public override function update()
        {
            x += 2;

            super.update();
        }
    }

The build (flash as target) works fine but when I run it there is the following run-time error:

[Fault] exception, information=TypeError: Error #1009: Cannot access a property or method of a null object reference.

It happens in the Image class in the HaxePunk source in this method:

    private inline function setBitmapSource(bitmap:BitmapData)
{
    _blit = true;
    _sourceRect = bitmap.rect;
    _source = bitmap;
}

The error is on the fourth line when asigning _sourceRect. The only thing I can think of is that bitmap.rect is null but the path to the image file is correct and the image is the correct format. Maybe I am missing something but the only difference in my code to the tutorial is the overriding the update function and the program does not even get there before crashing.

Any ideas on why this might be happening? (I can provide full source if you want)

Solution: changed the path to "gfx/mah.png" the problem was that in flash develop the generated embed code was incorrect, almost can't believe that was the solution!

0

There are 0 answers