[Papervision3D] upcasting DisplayObject3D

Ron Valstar ron at sjeiti.com
Mon Apr 2 05:31:06 EDT 2007


I have a class containing numerous cubes. Now I want to store the 
gridposition (=position*size) in the cubes.
I tried to make a class Block that extends the DisplayObject3D but I 
can't seem to cast the DisplayObject3D to Block.

The Block class looks like this:

package com.sjeiti.cubejunky {
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.core.proto.GeometryObject3D;
    public class Block extends DisplayObject3D {
        public var iX:int;
        public var iY:int;
        public var iZ:int;
        public function Block( name:String=null, 
geometry:GeometryObject3D=null, initObject:Object=null ):void {
            super(name,geometry,initObject);
        }
    }
}

I tried to cast it like this:

var oCube:Mesh3D = new 
Cube(aMat[iType],iBlockSize,iBlockSize,iBlockSize,1,1,1);
//var mCube:DisplayObject3D = oScene.addChild( oCube );
var mBlock:Block = (Block)( oScene.addChild(oCube) );

And I get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert 
org.papervision3d.objects::Cube at ab200d1 to com.sjeiti.cubejunky.Block.

I could of course easily make a container class where the 
DisplayObject3D is a public variable, but I just thought extending would 
look much nicer.

anybody have a solution?


thanks...

Ron




More information about the Papervision3D mailing list