[Papervision3D] upcasting DisplayObject3D
Ron Valstar
ron at sjeiti.com
Mon Apr 2 06:15:19 EDT 2007
Ah ok... it's working.
I forgot about the casting and extended the Cube, so now I create Blocks
and the addchild returns Blocks.
(still don't really have the hang of oo)
thanks
Ralph Hauwert wrote:
> Ron,
>
> I'm not sure I'm totally following, but your code shows that you want
> to cast the Cube class to a Block class. (the oScene.addChild(oCube)
> would return the add cube object).
>
> Regards,
> Ralph.
>
> On 4/2/07, Ron Valstar <ron at sjeiti.com> wrote:
>
>> 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
>>
>>
>> _______________________________________________
>> Papervision3D mailing list
>> Papervision3D at osflash.org
>> http://osflash.org/mailman/listinfo/papervision3d_osflash.org
>>
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/papervision3d_osflash.org/attachments/20070402/856148d4/attachment-0001.htm
More information about the Papervision3D
mailing list