Search code examples
actionscript-3flashactionscriptflash-builder

Error 1119 when trying to access properties of the graphic which is an Image in flashpunk?


I created a new entity and defined the entities graphic as a new Image from an embedded image files.

graphic = new Image(PLAYER);

PLAYER is an embedded image, now since graphic is this image now, I should be able to do things like centerOrigin() or angle(), but I can't? It worked in the Flash IDE but now that i've switched to Flash Builder for using flashpunk, It gives me an error 1119, cannot access property centerOrigin() through static type net.flashpunk:Graphic.

What am I doing wrong? A lot of tutorials say it should work. If it is supposed to work but the problem is the environment and not my program, what is a workaround?

Here's my actual code:

public class Projectile extends Entity{

    public var bearingIN:Number;
    public var speedIN:Number;

    public function Projectile(bearing,speed,gunX,gunY) {
        setHitbox(2,2);
        bearingIN = bearing;
        speedIN = speed;
        graphic = new Image(new BitmapData(8,1,false,0xFFFF32));
        type = "projectile";
        graphic.centerOrigin();
        graphic.angle = (bearing / (Math.PI/180))*-1;
        layer = 255
        x = gunX + 16;
        y = gunY + 16;
        addTween(new Alarm(20,removeProj,2), true);
    }

    private function removeProj(){
        FP.world.remove(this);
    }

    public override function update():void{
        x += Math.cos(bearingIN)*speedIN;
        y += Math.sin(bearingIN)*speedIN;
        if(collide("wall",x,y)){
            removeProj();
        }
    }

}

Solution

  • The graphic property of the Entity class is of type Graphic. However, the Graphic class has no method called centerOrigin only Image does. So you need to cast it. Do this for the line with centerOrigin():

    ((Image)graphic).centerOrigin();
    

    You'll have to do the same thing for angle as well.