[SOLVED] My program passes the compiler, and then immediately fails with strange error


(Helios) #1
ReferenceError: Error #1069: Property 0 not found on builtin.as$0.MethodClosure and there is no default value.
	at actors::Player/update()
	at net.flashpunk::World/update()
	at net.flashpunk::Engine/update()
	at net.flashpunk::Engine/onEnterFrame()

has anyone ever encounterred this error before? Its not even pointing me to somewhere I can fix, so I’m not sure what to do


(Ultima2876) #2

Sounds like a syntax problem. Can you paste your code for the Player class (more specifically the update function)?


(Helios) #3

sure! and I appreciate the help! I’m tracking it down and it looks like the problem is that I’m experimenting with object composition and delegation - it doesnt like me for it.

	public class Player extends Entity 
        {
	     private var speed:Number = 20;
	
	     public function Player() 
	     {
		controls = new controlBehavior();
		graphic = new Image(new BitmapData(/*etc*/));
	     }
	
	     override public function update():void 
	     {
		this.x += controls.movement[0] * speed
		this.y += controls.movement[1] * speed
	     }

	
	/*behaviors*/
	private var controls:controlBehavior
	
	
        }

(Helios) #4

heres the movement function it refers to in the control object reference Cntrl.up etc are constants

	public function movement():Point
	{
		var x:Number = 0;
		var y:Number = 0;
		
		var left:int = Cntrl.left;
		var right:int = Cntrl.right;
		var up:int = Cntrl.up;
		var down:int = Cntrl.down;
		
		if (Input.check(left))  { x-- }
		if (Input.check(right)) { x++ }
		if (Input.check(up))    { y-- }
		if (Input.check(down))  { y++ }
		
		return new Point(x, y);
	}

(Helios) #5

Oh okay, I got it working, you were absolutely right. the problem was I was accessing x and y in my point objects as though they were elements in an array, i.e. point[0] and point[1] instead of point.x and point.y


(Ultima2876) #6

Sorry I didn’t respond again earlier, was quite busy and have only just come back to check the response. Glad you got it sorted out though!