PDA

View Full Version : Interface & Type Coercion failure


jaga
01-23-2008, 05:54 PM
I'm retooling my physics engine with interfaces in order to use better OOP practices, and I've run into what I think is a simple hitch, but I can't quite figure out.

I have an interface IPhysicsEntity.as

package PhysicsSystem {
public interface IPhysicsEntity {
function physicsUpdate():void;
}
}


and I have a function in another location:

public function addObject(whichObject:IPhysicsEntity):void {
objectArray.push(whichObject);
}


and I'm passing into the addObject function something that implements IPhysicsEntity..


import PhysicsSystem.IPhysicsEntity;

public class PhysicsObject extends Sprite implements IPhysicsEntity {
/// et cetera


and I'm getting the following error:
TypeError: Error #1034: Type Coercion failed: cannot convert PhysicsObject@3135791 to PhysicsSystem.IPhysicsEntity.

Am I doing something obviously wrong?

jaga
01-23-2008, 08:51 PM
Just for sake of closure, there is nothing wrong with this code.

*sigh*
Was working out of a hodgepodge projects folder, where there happened to be a same-named script in the root folder. I was importing the correct script, but not using a package reference in creating a new instance, and flash was being nice enough to ignore my direct import and instead use the local file..

Annoying and trivial, of course