Simulating the Camera Effect in Flex using Flash Player 10

4 Jun
2008
Delicious

This example is almost a replica of PaperVision3D concrete example with the camera, except that it uses the native API that comes in Flash Player 10 for Flex. Need Flash Player to view it below

Here is an Example, you need to click first with the mouse to bring focus and move with the keys (w,a,s,d)

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:exhdLib="exhdLib.*"
	  paddingTop="30" backgroundColor="0xFFFFFF"
	   creationComplete="initApp()">
	  <mx:Script>
	  	<![CDATA[
	  		import mx.core.UIComponent;
	  		private var aKeyDown:Boolean;
	  		private var sKeyDown:Boolean;
	  		private var dKeyDown:Boolean;
	  		private var wKeyDown:Boolean;
 
	  		[Embed(@source="concr.jpg")]
	  		private var concretePic:Class;
 
	  		private var concreteHolder:UIComponent = new UIComponent();
 
	  		private function initApp():void
	  		{
 
	  			var bitmap:Bitmap = new concretePic();
	  			bitmap.rotationX=90;
	  			bitmap.x = -260;
				bitmap.y=250;
	  			concreteHolder.addChild(bitmap);
	  			addChild(concreteHolder);
	  			addEventListener(MouseEvent.CLICK,onMouseClick);
	  		}
 
	  		private function onMouseClick(event:MouseEvent):void
	  		{
	  			concreteHolder.setFocus();
	  			addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
	  			addEventListener(KeyboardEvent.KEY_UP,onKeyUp);
	  			addEventListener(Event.ENTER_FRAME,onEnterFrame);
	  		}
 
	  		private function onKeyDown(event:KeyboardEvent):void
	  		{
	  			// W: 87 , A: 65, S: 83 , D: 68
				switch(event.keyCode)
	  			{
	  				case 87:
	  					wKeyDown=true;
	  				break;
	  				case 65:
	  					aKeyDown=true;
	  				break;
	  				case 83:
	  					sKeyDown=true;
	  				break;
	  				case 68:
	  					dKeyDown =true;
	  				break;
 
	  			}
	  		}
	  		private function onKeyUp(event:KeyboardEvent):void
	  		{
	  			switch(event.keyCode)
	  			{
	  				case 87:
	  					wKeyDown=false;
	  				break;
	  				case 65:
	  					aKeyDown=false;
	  				break;
	  				case 83:
	  					sKeyDown=false;
	  				break;
	  				case 68:
	  					dKeyDown =false;
	  				break;
	  			}
	  		}
	  		private function onEnterFrame(event:Event):void
	  		{
	  			if(aKeyDown)
	  				concreteHolder.rotationY+=10;
	  			if(sKeyDown)
	  				concreteHolder.z+=10;
	  			if(dKeyDown)
	  				concreteHolder.rotationY-=10;
	  			if(wKeyDown)
	  				concreteHolder.z-=10;
 
	  		}
 
 
	  	]]>
	  </mx:Script>
 
</mx:Application>
Incoming Search Terms :flex camera example , as3 3d camera player 10 , 3d as3 nativeAPI camera , sample flash player 10 cam , flex simulate web camera , flex effect , flash player 10 camera , effects in flex , camera flash effect as3 , camera effect in as3

Share this story with a friend !
Join SherifAbdou's Rss Feed Stumble This Article! Add this to your Delicious Bookmarks! Digg this story ! Add this story to Reddit ! Tweet This Brush


4 Responses to Simulating the Camera Effect in Flex using Flash Player 10

Avatar

bluemetalNo Gravatar

June 4th, 2008 at 7:14 pm

rotation center looks always same position

Avatar

Mihail MirchevNo Gravatar

August 29th, 2008 at 12:50 am

What if I want to “look” up/down and then left/right?

Avatar

SherifNo Gravatar

August 29th, 2008 at 1:01 am

Then You could Play around with rotationX and RotationY and rotationZ

Avatar

daemonnaNo Gravatar

May 28th, 2009 at 1:35 pm

great! finally dont need papervision and other frameworks :)

Comment Form