Graphiclist problem can't figure out?


(Sharon Shalom Iluz) #1

I have a water animation entity and i want to add it to the background entity i gave up this idea and adding to the world but it still doesn’t work.

i am thinking now Backdrop can’t be put in Graphiclist ??? but in the document it says:

A Graphic that can contain multiple Graphics of one or various types. Useful for drawing sprites with multiple different parts, etc.

can any one help me please

public class WaterEntity extends Entity
{

    private var waterPart1:Backdrop = new Backdrop(HD_Assets.WATER_FRONT);
    private var waterPart2:Backdrop = new Backdrop(HD_Assets.WATER_BACK);

    public var speed:Number = 2;

    private var background:Graphiclist;

    public function WaterEntity()
    {
        super();

    }

    override public function added():void
    {
        super.added();


        waterPart1 = new Backdrop(HD_Assets.WATER_FRONT, true, false);
        waterPart1.y = FP.screen.height - waterPart1.height;

        waterPart2 = new Backdrop(HD_Assets.WATER_BACK, true, false);
        waterPart2.y = FP.screen.height - waterPart1.height +5;

        background.add(waterPart1);
        background.add(waterPart2);

        graphic = background;

    }

    override public function update():void
    {
        waterPart1.x += speed;
        waterPart2.x -= speed + 3;
    }

}

(TaylorAnderson) #2

It looks like you never actually instantiate the graphiclist–you never say background = new Graphiclist anywhere.


(Sharon Shalom Iluz) #3

lol im sorry im very new to programming thanks a lot.


(TaylorAnderson) #4

No problem! If thats all you need, you should add [SOLVED] to the title of the post


(Jacob Albano) #5

This is where reading the error messages can be very helpful. The one you got probably said something like “Cannot access a property on a null object reference.”

What’s a null reference? It’s a variable that hasn’t been set to anything. So if your graphiclist object is nulll…: :bulb:

This is also why we always ask for the exact text of the error you get. ;) It helps everyone out.