AS3/Papervision  can I nest a 3D text using DisplayObject3D

mankis
mankis used Ask the Experts™
on
I have  text Class for displaying text in 3D papervision. I'm trying to learn how to nest this 3D text with other object. You can see code attached. With this code I'm getting error:
1067: Implicit coercion of a value of type TextNested to an unrelated type org.papervision3d.objects:DisplayObject3D.
so this is probably the wrong way. Do you know some tutorial or is there some other way to to that?
package {
	import flash.events.Event;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.*;

	public class TestPivot extends BasicView {
		private var pivot3D:DisplayObject3D;
		private var easeOut:Number = 0.6;
		private var reachX:Number = 0.5;
		private var reachY:Number = 0.5;
		private var reachZ:Number = 0.5;
		
		public function TestPivot() {
			pivot3D= new DisplayObject3D();
			init();
			startRendering();
		}
		private function init():void {

			scene.addChild(pivot3D);

			var sfera:Sphere = new Sphere(null,100,12,8);
			sfera.x=400;
			pivot3D.addChild(sfera);
			
			var plan:Plane = new Plane(null,300,300,8,8);
			plan.x=-100;
			pivot3D.addChild(plan);
			
			var tekst:TextNested = new TextNested("test 3D tekst",stage.stageWidth,stage.stageHeight);
			tekst.x=-300;
			pivot3D.addChild(tekst);
		}
		override protected function onRenderTick(e:Event=null):void {
			var xDist:Number = mouseX - stage.stageWidth * 0.5;
			var yDist:Number = mouseY - stage.stageHeight * 0.5;
			camera.x += (xDist - camera.x * reachX) * easeOut;
			camera.y += (yDist - camera.y * reachY) * easeOut;
			//camera.z += (-mouseY * 2 - camera.z ) * reachZ;
			super.onRenderTick();
		}
	}
}

Open in new window

package {
	import flash.events.Event;
	import org.papervision3d.materials.special.Letter3DMaterial;
	import org.papervision3d.typography.Font3D;
	import org.papervision3d.typography.Text3D;
	import org.papervision3d.typography.fonts.Square721BT;
	import org.papervision3d.view.BasicView;

	public class TextNested extends BasicView {
		private var material:Letter3DMaterial;
		private var font3D:Font3D;
		private var text3D:Text3D;
		private var easeOut:Number = 0.6;
		private var reachX:Number = 0.5;
		private var reachY:Number = 0.5;
		private var reachZ:Number = 0.5;
		private var text:String;
		private var stagewidth:Number;
		private var stageheight:Number;

		public function TextNested(teksts:String,stagew:Number,stageh:Number) {

			text = teksts;
			stagewidth = stagew;
			stageheight = stageh;
			init();
			
		}
		private function init():void {
			material = new Letter3DMaterial(0xFFFFFF);
			font3D = new Square721BT();
			text3D = new Text3D(text,font3D,material);
			
			text3D.scale = 0.5;
			text3D.align = "left";
			text3D.letterSpacing = -3;
			text3D.lineSpacing = -30;
			text3D.material.lineThickness = 0;
			text3D.material.lineAlpha = 1;
			text3D.material.lineColor = 0xFF0000;
			//scene.addChild(text3D);


		}
	}
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I have already found tutorial for my question so I will attach the code and close the question
package 
{
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.text.*;
	import flash.filters.*;
	import flash.utils.getTimer;
	import org.papervision3d.core.clipping.FrustumClipping;
	import org.papervision3d.core.proto.MaterialObject3D;
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.MovieMaterial;
	import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
	import org.papervision3d.materials.special.CompositeMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.materials.WireframeMaterial;
	import org.papervision3d.objects.*;
	import org.papervision3d.objects.primitives.*;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.cameras.*;
	import org.papervision3d.materials.special.Letter3DMaterial;
	import org.papervision3d.typography.fonts.HelveticaBold;
	import org.papervision3d.typography.Text3D;
	import org.papervision3d.core.effects.view.ReflectionView;
	import caurina.transitions.properties.CurveModifiers;
	import caurina.transitions.Tweener;
	
	[SWF(width = "720", height = "480", frameRate = "60", backgroundColor = "0")]
	
		
	public class Main extends ReflectionView
	{
		static private const ROUND           :uint = 2000;
		static private const OBJ_AMOUNT      :uint = 30;
		static private const CAMERA_POSITION :uint = 2000;
		static private const PLANE_SIZE      :uint = 5000;
		static private const COLOR_LIST      :Array  = [0x003399, 0x0066CC, 0x0099FF, 0x33CCFF];
		
		private var wraps:Array = [];
		private var words:Array = [];
		private var wrapRoot:DisplayObject3D;
		
		public function Main():void 
		{
			super(0, 0, true , false, CameraType.TARGET);
			
			camera.zoom = 1.5;
			camera.focus = 200;
			
			// refrection
			surfaceHeight = 0;
			//viewportReflection.filters = [new BlurFilter(2, 2, 3)];
			viewportReflection.alpha = .25;
			
			// safe polygon
			renderer.clipping = new FrustumClipping(FrustumClipping.NEAR)
			
			// add material
			var compMat:CompositeMaterial = new CompositeMaterial();
			compMat.addMaterial(new WireframeMaterial(0xEEEEEE));
			compMat.addMaterial(new ColorMaterial(0xEEEEEE, 0.1));
			
			var planeB:Plane = new Plane(compMat, PLANE_SIZE, PLANE_SIZE, 6, 6);
			planeB.pitch(90)
			scene.addChild(planeB);
			
			wrapRoot = scene.addChild(new DisplayObject3D());
			
			// particle motion
			var cnt:int = 0;
			for (var i:int = 0; i < OBJ_AMOUNT; i++ )
			{
				var wrap:DisplayObject3D = wrapRoot.addChild(new DisplayObject3D());
				wrap.y = ROUND * Math.random();
				wraps.push(wrap);
				
				// A-Z
				var char:String = String.fromCharCode(65 + 25 * Math.random() | 0);
				
				// letter
				var lettermat:Letter3DMaterial = new Letter3DMaterial();
				lettermat.fillColor = COLOR_LIST[ COLOR_LIST.length * Math.random() | 0];
				var word:Text3D = new Text3D(char , new HelveticaBold() , lettermat);
				
				word.z = 500 * Math.random() + 1000;
				word.rotationY = 360 * Math.random();
				word.scale = 5 * Math.random() + 0.5;
				wrap.addChild(word);
				
				words.push(word)
			}
			
			//startRendering();
			resizeHandler();
			stage.addEventListener(Event.RESIZE, resizeHandler);
			stage.addEventListener(Event.ENTER_FRAME, loop)
		}
		
		private function loop(event:Event = null):void 
		{
			var i:int = wraps.length;
			while (i--) wraps[i].rotationY += i / 25;
			
			i = words.length;
			while (i--) words[i].rotationY += 4;
			
			camera.x += (CAMERA_POSITION * Math.sin(mouseX / stage.stageWidth * 360 * Math.PI / 180) - camera.x) * .1;
			camera.z += (CAMERA_POSITION * Math.cos(mouseX / stage.stageWidth * 360 * Math.PI / 180) - camera.z) * .1;
			camera.y += (CAMERA_POSITION * mouseY / stage.stageHeight - camera.y) * .1;
			
			singleRender();
		}
		
		private function resizeHandler(e:Event = null):void
		{
			graphics.clear();
			graphics.beginFill(0x001122);
			graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
		}
	}
}

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial