[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

as3: add movieclip to pv3d plane to use as an image loader

Posted on 2009-12-27
10
Medium Priority
?
773 Views
Last Modified: 2013-11-11
I am trying to add movieclips to the individual planes on the carousel, so that I can add images to the planes.  What is my next step here?

Creating a carousel with this pv3d class and want to use the planes as image loaders or add a mc to the planes so that the rotation stays, but i can then add images to the planes...
package {
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Point;

	import fl.transitions.easing.*;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.utils.*;
	import flash.events.MouseEvent;
	import flash.display.Sprite;
	import flash.display.BitmapData;
	import flash.geom.Point;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.view.BitmapViewport3D;

	[SWF(width="940",height="300",backgroundColor="#ffffff",frameRate="60")]
	public class InternalCarousel extends BasicView {
		private static const NUMBER_OF_PLANES:int=11;

		private var carousel:DisplayObject3D=new DisplayObject3D  ;
		private var bitmapViewport:BitmapViewport3D=new BitmapViewport3D(940,300);
		private const blur:BlurFilter=new BlurFilter(0,0,0);
		private const alphaTrans:ColorTransform=new ColorTransform(1,1,1,1,1,1,1,-35);
		private var point:Point=new Point  ;
		trace("this is working");


		public function InternalCarousel() {
			bitmapViewport.fillBeforeRender=false;
			addChild(bitmapViewport);
			camera.z=1;
			for (var i:int=0; i<NUMBER_OF_PLANES; i++) {
				var randomColor:Number=Math.random()*0xffffff;
				var colorMaterial:ColorMaterial=new ColorMaterial(randomColor);
				colorMaterial.doubleSided=true;

				var plane:Plane=new Plane(colorMaterial,360,280);
				plane.rotationY=360/NUMBER_OF_PLANES*i;
				plane.moveForward(900);
				carousel.addChild(plane);
				trace("plane = "+plane);

				var picLoader:Sprite=new Sprite  ;
				addChild(picLoader);
				picLoader.graphics.beginFill(0x00FF00,1);
				picLoader.graphics.drawRect(0,0,180,150);
				picLoader.graphics.endFill();
				picLoader.rotationY=360/NUMBER_OF_PLANES*i;
				picLoader.x=plane.x;
				picLoader.y=plane.y;
			}

			scene.addChild(carousel);

			startRendering();
		}

		override protected function onRenderTick(event:Event=null):void {
			carousel.rotationY-=viewport.containerSprite.mouseX/200;

			renderer.renderScene(scene,camera,bitmapViewport);
			bitmapViewport.bitmapData.applyFilter(bitmapViewport.bitmapData,bitmapViewport.bitmapData.rect,point,blur);
			bitmapViewport.bitmapData.colorTransform(bitmapViewport.bitmapData.rect,alphaTrans);
		}
	}
}

Open in new window

0
Comment
Question by:cubical38
  • 5
  • 5
10 Comments
 
LVL 4

Expert Comment

by:72lions
ID: 26130328
Instead of a ColorMaterial use a MovieMaterial. In the following example you will change the shape with tha name fo the MovieClip that you want to use:

You can also check the following:

http://pv3d.org/tag/moviematerial/
http://flashenabledblog.com/2008/05/14/video-tutorial-pv3d-interactive-moviematerial-and-cube-navigation/


var material:MovieMaterial = new MovieMaterial(shape);
//animated needs to be true to tween the color
material.animated = true;
material.doubleSided = true;
material.interactive = true;
 
var plane:Plane = new Plane(material, 100, 100);

Open in new window

0
 

Author Comment

by:cubical38
ID: 26131772
Excellent thanks for the reply.  One question...  How do i then target each individual plane?  As to say if I want a MOUSE_OVER and or CLICK for each material.

Thanks!


public function InternalCarousel() {
			bitmapViewport.fillBeforeRender=false;
			addChild(bitmapViewport);
			camera.z=1;
			for (var i:int=0; i<NUMBER_OF_PLANES; i++) {
				/*var randomColor:Number=Math.random()*0xffffff;
				var colorMaterial:ColorMaterial=new ColorMaterial(randomColor);
				colorMaterial.doubleSided=true;*/
				var picLoader:Sprite=new Sprite;
				
				picLoader.graphics.beginFill(0x00FF00,1);
				picLoader.graphics.drawRect(0,0,180,150);
				picLoader.graphics.endFill();
				picLoader.rotationY=360/NUMBER_OF_PLANES*i;
				//addChild(picLoader);
				
				var material:MovieMaterial=new MovieMaterial(picLoader);

				material.animated=true;
				material.doubleSided=true;
				material.interactive=true;
				material.addEventListener(MouseEvent.MOUSE_OVER, tellMeSomething);
				function tellMeSomething(event:MouseEvent):void {
					trace("something good");
				}

				var plane:Plane=new Plane(material,360,280);
				
				plane.rotationY=360/NUMBER_OF_PLANES*i;
				plane.moveForward(900);
				carousel.addChild(plane);
				trace("plane = "+plane);
			}

			scene.addChild(carousel);

			startRendering();
		}

Open in new window

0
 

Author Comment

by:cubical38
ID: 26131920
Ive tried the following but the stage is blank upon testing:
var picLoader:Sprite=new Sprite  ;

				picLoader.graphics.beginFill(0x00FF00,1);
				picLoader.graphics.drawRect(0,0,180,150);
				picLoader.graphics.endFill();
				picLoader.rotationY=360/NUMBER_OF_PLANES*i;

				var material:MovieMaterial=new MovieMaterial(picLoader);

				material.animated=true;
				material.doubleSided=true;
				material.interactive=true;
				plane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,tellMeSomething);

				function tellMeSomething(event:InteractiveScene3DEvent):void {
					trace("something good");
				}

				var plane:Plane=new Plane(material,360,280);

				plane.rotationY=360/NUMBER_OF_PLANES*i;
				plane.moveForward(900);
				carousel.addChild(plane);

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Expert Comment

by:72lions
ID: 26131931
You will add the listeners to each movieclip and then you have to add the following line:

bitmapViewport.interactive=true
0
 

Author Comment

by:cubical38
ID: 26132150
I am unable to add the event LIstener.  Nothing happens if I add ot to picLoader, material or plane.  The only way I am even able to see interactivity is if I add the listener to bitmapViewport.  Do I need to drill down into the bitmapViewport?  ie: bitmapViewport.picLoader


public function InternalCarousel() {
			bitmapViewport.fillBeforeRender=false;
			addChild(bitmapViewport);
			bitmapViewport.interactive=true;
			camera.z=1;
			for (var i:int=0; i<NUMBER_OF_PLANES; i++) {
				var picLoader:MovieClip=new MovieClip  ;

				picLoader.graphics.beginFill(0x00FF00,1);
				picLoader.graphics.drawRect(0,0,180,150);
				picLoader.graphics.endFill();
				picLoader.rotationY=360/NUMBER_OF_PLANES*i;

				var material:MovieMaterial=new MovieMaterial(picLoader);

				material.animated=true;
				material.doubleSided=true;
				material.interactive=true;
				//picLoader.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,tellMeSomething);
				picLoader.addEventListener(MouseEvent.MOUSE_OVER,tellMeSomething);

				function tellMeSomething(event:MouseEvent):void {
					trace("something good");
				}


				var plane:Plane=new Plane(material,360,280);

				plane.rotationY=360/NUMBER_OF_PLANES*i;
				plane.moveForward(900);
				carousel.addChild(plane);
			}

Open in new window

0
 
LVL 4

Expert Comment

by:72lions
ID: 26132236
The InteractiveScene3DEvent is added to a 3D object, e.x. a Plane. So try doing the following:
plane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,tellMeSomething);

Open in new window

0
 
LVL 4

Expert Comment

by:72lions
ID: 26132259
If you still have problem please send me the class file and the fla file so that I can check it.
0
 

Author Comment

by:cubical38
ID: 26132353
Yea I am now getting:
1150: The protected attribute can only be used on class property definitions.
Archive.zip.txt
0
 
LVL 4

Accepted Solution

by:
72lions earned 2000 total points
ID: 26133316
I changed you file and it works fine. Now, you will see that on the tellmesomething function I added a couple of lines which get you access to the material (movieclip) of the plane that you mouse over.

Something else. You can't have an interactive scene with an BitmapViewport3D so I changed it to a simple Viewport3D. This had as a result your filters not to work. But search google for "pv3d EffectLayer" and you will find examples on how to use filters on your scene.
InternalCarousel.as.txt
0
 

Author Closing Comment

by:cubical38
ID: 31670298
PERFECT!  Thanks for all the help.  I will search for the best way to add a filter.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question