<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Team Blog</title>
	<atom:link href="http://www.carlosrovira.com/teamblog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.carlosrovira.com/teamblog</link>
	<description>Individual Toughts and Experiences in a Hive</description>
	<pubDate>Thu, 27 Nov 2008 15:21:42 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Video with reflection on a 3D Plane</title>
		<link>http://www.carlosrovira.com/teamblog/2008/11/27/video-with-reflection-on-a-3d-plane/</link>
		<comments>http://www.carlosrovira.com/teamblog/2008/11/27/video-with-reflection-on-a-3d-plane/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 15:20:23 +0000</pubDate>
		<dc:creator>Carlos Rovira</dc:creator>
		
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://www.carlosrovira.com/teamblog/?p=10</guid>
		<description><![CDATA[Next, we deal with a PV3D class that shows a video playing upon a 3D plane made with Papervision. You can see a reflection behind the video with a blur effect using the integrated effect branch. This was developed some months ago thinking in our new site, but finaly, due to time constraints, it was [...]]]></description>
			<content:encoded><![CDATA[<p>Next, we deal with a PV3D class that shows a video playing upon a 3D plane made with Papervision. You can see a reflection behind the video with a blur effect using the integrated effect branch. This was developed some months ago thinking in our <a href="http://www.carlosrovira.com">new site</a>, but finaly, due to time constraints, it was left for future versions.  </p>
<p>The example uses BasicView as the superclass to ensure all things all already setup for you (camera, width, height, scene, viewport,&#8230;).</p>
<p>Here is the final example running:</p>
<div align="center">
<object type="application/x-shockwave-flash" width="400" height="500">
<param name="movie" value="http://www.carlosrovira.com/teamblog/uploads/videoOnPlane/VideoOnPlane.swf" />
<embed src="http://www.carlosrovira.com/teamblog/uploads/videoOnPlane/VideoOnPlane.swf" type="application/x-shockwave-flash" width="400" height="500" >
</object>
</div>
<p><span id="more-10"></span></p>
<p>You can explore and download the source coder <a href="http://www.carlosrovira.com/teamblog/uploads/videoOnPlane/srcview/">here</a>.</p>
<p>The following is the sorce code of the main class. Hope you find it interesting: </p>
<pre class="syntax-highlight:javascript">package {
	import flash.display.BitmapData;
	import flash.display.GradientType;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.NetStatusEvent;
	import flash.filters.BlurFilter;
	import flash.geom.Matrix;
	import flash.media.Video;
	import flash.net.NetConnection;
	import flash.net.NetStream;

	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.VideoStreamMaterial;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;

    [SWF(backgroundColor=&quot;#FFFFFF&quot;)]
	public class VideoOnPlane extends BasicView
	{
		private var ns:NetStream;
		private var v:Video;
		private var plane:Plane;
		private var reflectionPlane:Plane;
		private var vm:VideoStreamMaterial;
		private var bm:BitmapMaterial;
		private var matrix:Matrix;
		private var gradientMask:Sprite;

		private function initVideo():void {
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;

			var nc:NetConnection = new NetConnection();
			nc.connect(null);

			ns = new NetStream(nc);
			ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
			ns.play(&quot;video/phone.flv&quot;);

			v = new Video();
			v.attachNetStream(ns);
		}

		public function VideoOnPlane(viewportWidth:Number=400, viewportHeight:Number=300, scaleToStage:Boolean=true, interactive:Boolean=false, cameraType:String=&quot;CAMERA3D&quot;)
		{
			super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);

			camera.focus = 400;
			camera.zoom = 2;

			initVideo();			

			vm = new VideoStreamMaterial(v, ns, true);
			vm.smooth = true;
			vm.doubleSided = true;

			plane = new Plane(vm, v.width, v.height);
			scene.addChild(plane);

			bm = new BitmapMaterial(new BitmapData(v.width, v.height), true);
			bm.doubleSided = true;

			reflectionPlane = new Plane(bm, v.width, v.height);
			reflectionPlane.rotationX = 180;
			reflectionPlane.y = -v.height
			scene.addChild(reflectionPlane);

			reflectionPlane.createViewportLayer(viewport, false).filters = [new BlurFilter()];

			matrix = new Matrix();
			matrix.createGradientBox(v.width, v.height, (90/180)*Math.PI, 0, 90);

			gradientMask = new Sprite();
			gradientMask.graphics.beginGradientFill(GradientType.LINEAR, [0xFFFFFF, 0xFFFFFF], [1, 0.4], [0, 255], matrix);
			gradientMask.graphics.drawRect(0,0,v.width, v.height);
			gradientMask.graphics.endFill();
			gradientMask.cacheAsBitmap = true;

			startRendering();
		}

		protected override function onRenderTick(event:Event = null):void {
			//plane.yaw(1);
			//reflectionPlane.yaw(-1);

			plane.rotationY = -35;
			reflectionPlane.rotationY = -35;

			reflectPicture();

			super.onRenderTick(event);
		}

		private function reflectPicture():void {
			bm.bitmap.draw(plane.material.bitmap);
			bm.bitmap.draw(gradientMask);
		}

		private function onNetStatus(e:NetStatusEvent):void {
			switch (e.info.code) {
        		case &quot;NetConnection.Connect.Success&quot;:
	            	trace(&quot;successfully connected&quot;);
	       	     	break;
				case &quot;NetStream.Play.StreamNotFound&quot;:
	            	trace(&quot;Unable to locate video: &quot;);
	            	break;
				case &quot;NetStream.Buffer.Full&quot;:
					trace(&quot;buffer full&quot;);
					break;
				case &quot;NetStream.Buffer.Empty&quot;:
					trace(&quot;buffer empty&quot;);
					break;
				case &quot;NetStream.Play.Stop&quot;:
					trace (&quot;video finished&quot;);
					ns.seek(0);
					ns.pause();
					break;

        	}
		}
	}
}
</pre>
<p>Hope you enjoy this example and start trying Papervision3D to show us what you can do!</p>]]></content:encoded>
			<wfw:commentRss>http://www.carlosrovira.com/teamblog/2008/11/27/video-with-reflection-on-a-3d-plane/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flex Component Architecture by example (II)</title>
		<link>http://www.carlosrovira.com/teamblog/2008/10/16/flex-component-architecture-by-example-ii/</link>
		<comments>http://www.carlosrovira.com/teamblog/2008/10/16/flex-component-architecture-by-example-ii/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 11:26:41 +0000</pubDate>
		<dc:creator>Gonzalo Rodriguez Pezzi</dc:creator>
		
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.carlosrovira.com/teamblog/?p=18</guid>
		<description><![CDATA[In my last post, I explained how to create a simple component: a shape inside the blackboard. As we want to enable the user to draw diferent shapes, we will have to learn how to create the blackboard component, in wich we will be able to draw shapes using the mouse. So the blackboard component [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post, I explained how to create a simple component: a shape inside the blackboard. As we want to enable the user to draw diferent shapes, we will have to learn how to create the blackboard component, in wich we will be able to draw shapes using the mouse. So the blackboard component will hold some instances of the BlackboardShape component we built in the <a href="http://www.carlosrovira.com/teamblog/2008/09/11/flex-component-architecture-by-example-i/">previous </a>part of this tutorial.</p>
<p>Let&#8217;s go with the next part of this article</p>
<p><span id="more-18"></span></p>
<p>You can see the whole example working <a href="http://www.carlosrovira.com/teamblog/uploads/Componentes/BlackboardApp.html">here</a>. Press right button -> View Source to see the full source code. </p>
<h3>MOUSE EVENTS</h3>
<p>I assume you have already worked with Actionscript events. However, let&#8217;s explain it just in case you don&#8217;t remember.<br />
You can listen to any events dispatched by an Actionscript object just by writing this code:<br />
<em><br />
object.addEventListener (eventType, eventHandler)</em></p>
<p>The eventHandler is a function that will be executed everytime the event is dispatched. </p>
<p>For example:</p>
<p><em>object.addEventListener (MouseEvent.MOUSE_DOWN, mouseDownEventHandler);</em></p>
<p><em>private function mouseDownHandler (event : MouseEvent) : void {<br />
&#8230;<br />
}<br />
</em><br />
The event object we receive as a parameter contains useful information to handle the event and perform some actions. </p>
<p>In our example, we will use these events: </p>
<ul>
<li>MouseEvent.MOUSE_DOWN: it happens when we press the left button of the mouse</li>
<li>MouseEvent.MOUSE_UP: it happens when we release the left mouse button</li>
<li>MouseEvent.MOUSE_OUT: it is dispatched when we move the cursor out of the component</li>
<li>MouseEvent.MOUSE_MOVE: it is dispatched when we move the cursor along the component.</li>
</ul>
<p>If we create an empty component and try to listen to mouse events, we will see that no event is dispatched. This happens because they will only be dispatched if we have drawn something inside the component. So, in order to catch the mouse events, I have drawn a transparent sprite on top of the component that will listen to the mouse events (cristal).</p>
<h3>COMPONENT STATES</h3>
<p>When creating our component, there are some rules that we should keep in mind: </p>
<ul>
<li>Update the visualization of the component only in the <em>updateDisplayList</em> function.</li>
<li>Never call directly to the <em>updateDisplayList</em> function. We should call the <em>invalidateDisplayList</em> function instead.</li>
</ul>
<p>This is a very simple component. If we create more complex components showing complex data, it will be necessary to use the commitProperties function.<br />
The easiest way to handle the diferent states of our component is to store the current state in a variable (blackboardState).<br />
We will use three states: </p>
<ul>
<li><strong>BASE</strong></li>
<li><strong>STARTING_PICTURE</strong>: the user is starting a new shape inside the blackboard</li>
<li><strong>DRAWING</strong>: the user is drawing</li>
</ul>
<p>Whenever we want to make a change to the component, we will change the state variable and call the <em>invalidateDisplayList </em>function if the visualization of the component must be refreshed. </p>
<h3>THE CODE</h3>
<p>Enough explanation. Let&#8217;s see the code:</p>
<pre class="syntax-highlight:javascript">
package comp
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Point;

	import mx.controls.Alert;
	import mx.controls.Button;
	import mx.core.UIComponent;

	public class Blackboard extends UIComponent
	{
		/* BLACKBOARD AVAILABLE STATES */
		private static const BASE : String = &quot;&quot;;
		private static const STARTING_PICTURE : String = &quot;startingPicture&quot;;
		private static const DRAWING : String = &quot;drawing&quot;;

		// The state variable will store the current state of the variable
		private var blackboardState : String = BASE;

		// We will use a transparent Sprite that will be displayed on top of the blackboard and will
		// capture mouse events
		private var cristal : Sprite;
		// The background
		private var background : Shape;

		// Reference to the shape we are working with
		private var currentShape : BlackboardShape;
		// The location of the mouse cursor
		private var cursorPosition : Point;

		public function Blackboard()
		{
			super();
		}

		// In this method we create the children of this component and make sure everything is correctly initialized
		override protected function createChildren():void {
			cristal = new Sprite ();
			cristal.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
			cristal.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
			cristal.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
			cristal.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);

			background = new Shape ();
		}

		// When we detect a mouseDown event, it means the user is starting a new drawing
		private function mouseDownHandler (event : MouseEvent) : void {
			blackboardState = STARTING_PICTURE;
			cursorPosition = new Point (event.localX, event.localY);
			currentShape = new BlackboardShape ();
			currentShape.x = cursorPosition.x;
			currentShape.y = cursorPosition.y;
			currentShape.addPoint (cursorPosition.x - currentShape.x, cursorPosition.y - currentShape.y);
			invalidateDisplayList();
		}

		// When we capture a mouseUp, it means the user stops drawing, so my component will return to the base state
		private function mouseUpHandler (event : MouseEvent) : void {
			blackboardState = BASE;
		}

		// If the user moves the mouse out of this component, the component will return to the base state
		// and the shape the user was drawing is finished
		private function mouseOutHandler (event : MouseEvent) : void {
			blackboardState = BASE;
		}

		// If the user was drawing a shape and moves the mouse, we must register a new point in the shape
		private function mouseMoveHandler (event : MouseEvent) : void {
			if (blackboardState==DRAWING) {
				cursorPosition = new Point (event.localX, event.localY);
				currentShape.addPoint (cursorPosition.x - currentShape.x, cursorPosition.y - currentShape.y);
				invalidateDisplayList();
			}
		}

		// This method configures the minimum and default size of the component
		override protected function measure():void {
			minHeight = measuredMinHeight = 300;
			minWidth = measuredMinWidth = 400;
		}

		// This method renders changes in the visualization of the component when necessary
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
			background.graphics.clear();
			background.graphics.beginFill(0xFFFFFF, 1);
			background.graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
			background.graphics.endFill();
			if (!this.contains(background)) {
				this.addChild(background);
			}

			if (blackboardState==STARTING_PICTURE) {
				this.addChildAt(currentShape, this.numChildren - 1);  // We make sure not to add the shape on top of the cristal that dispatches mouseEvents
				blackboardState = DRAWING;
			}

			// Update the cristal size to capture events. Just in case the size of the component has changed, I redraw it
			cristal.graphics.clear();
			cristal.graphics.beginFill(0xFFFFFF, 0);
			cristal.graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
			cristal.graphics.endFill();
			if (!this.contains(cristal)) {
				this.addChild(cristal);
			}

		}

	}
}
</pre>
<p>You can see the whole example working <a href="http://www.carlosrovira.com/teamblog/uploads/Componentes/BlackboardApp.html">here</a>. Press right button -> View Source to see the full source code. </p>]]></content:encoded>
			<wfw:commentRss>http://www.carlosrovira.com/teamblog/2008/10/16/flex-component-architecture-by-example-ii/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flex Component Architecture by example (I)</title>
		<link>http://www.carlosrovira.com/teamblog/2008/09/11/flex-component-architecture-by-example-i/</link>
		<comments>http://www.carlosrovira.com/teamblog/2008/09/11/flex-component-architecture-by-example-i/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 13:53:42 +0000</pubDate>
		<dc:creator>Gonzalo Rodriguez Pezzi</dc:creator>
		
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.carlosrovira.com/teamblog/?p=12</guid>
		<description><![CDATA[Today, I am going to show you how to create your own ActionScript Flex Components.
Creating Flex components is very easy, but you must know some things about the Flex Component Framework.

Bitmap Caching
The graphical performance of the Flash Player gets improved thanks to the bitmap caching feature. It enables the Flash Player to render the visual [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I am going to show you how to create your own ActionScript Flex Components.</p>
<p>Creating Flex components is very easy, but you must know some things about the Flex Component Framework.</p>
<p><span id="more-12"></span></p>
<h3>Bitmap Caching</h3>
<p>The graphical performance of the Flash Player gets improved thanks to the bitmap caching feature. It enables the Flash Player to render the visual elements just when needed. If a visual element doesn&#8217;t change during the execution of the application, a bitmap representation of that element will be shown in every frame instead of rendering it once and again. Only the visual elements marked as “dirty” will be redrawn.</p>
<p>More information on <em>Bitmap Caching</em> <a href="http://www.adobe.com/devnet/flash/articles/bitmap_caching.html">here</a>.</p>
<h3>Graphic Primitives</h3>
<p>When developing custom Flex Components, we will make intense use of graphic primitives. In a future post, I will talk about creating skinnable components, and it will allow us not to draw programatically, but using assets. </p>
<p>We will build a very simple blackboard component. We will achieve this: </p>
<p>
<object type="application/x-shockwave-flash" width="500" height="400">
<param name="movie" value="http://www.carlosrovira.com/teamblog/wp-content/uploads/2008/09/blackboardapp.swf" />
<embed src="http://www.carlosrovira.com/teamblog/wp-content/uploads/2008/09/blackboardapp.swf" type="application/x-shockwave-flash" width="500" height="400" >
</object>
</p>
<p>We are going to create two actionscript components: </p>
<ul>
<li><em>BlackboardShape</em>: it respresents every independent shape a user draws. It is made of different points connected with lines.</li>
<li><em>Blackboard</em>: the canvas where the users draws. It does all the event catching work.</li>
</ul>
<p>First of all, we will focus on the <em>BlackboardShape</em>, wich is a very simple Flex component. </p>
<p>This is the source code for that component:</p>
<pre class="syntax-highlight:javascript">package comp
{
	import comp.common.BlackboardPoint;

	import flash.filters.BevelFilter;

	import mx.core.UIComponent;

	public class BlackboardShape extends UIComponent
	{
		private var pointArray : Array;
		private var color : Number;

		public function BlackboardShape()
		{
			super();
			pointArray = new Array ();
			color = Math.random() * 0xFFFFFF;	  // This sets the color. We choose a random color.
			this.filters = [new BevelFilter ()];  // This adds a bevel filter to the shape wich will
							 	  // add that &quot;ketchup&quot; look
		}

		// Add a new point to the shape
		public function addPoint (x : Number, y : Number) : void {
			pointArray.push (new BlackboardPoint (x, y, false));
			// There is a new Point, so the shape must be redrawn. We call invalidateDisplayList, so
			// the framework will call updateDisplayList at the right time
			// in order to draw the next frame
			invalidateDisplayList();
		}

		// This method updates the visualization of the component.
		// You should NEVER call this method directly.
		// If you have to update the visualization of your component, call invalidateDisplayList ()
		// instead and the Flex Component Framework will call updateDisplayList for you at right time.
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
			var previousPoint : BlackboardPoint = new BlackboardPoint (0, 0, true);
			var point : BlackboardPoint;
			this.graphics.lineStyle(15, color);
			// We process every point in the shape.
			// We use graphic primitives to draw lines between the points
			for each (point in pointArray) {
				if (!point.processed) {
					if (previousPoint) {
						this.graphics.moveTo(previousPoint.x, previousPoint.y);
					}
					this.graphics.lineTo(point.x, point.y);
					point.processed = true;
				}
				previousPoint = point;
			}
		}
	}
}</pre>
<p>There is a public method <em>addPoint</em> that will be used by the <em>Blackboard</em> component when capturing mouse events. If you read that code you will see there are no graphic instructions: we only add a record to our Point Array. The <em>pointArray</em> property stores the points that define the shape. At the end of the method, we call <em>invalidateDisplayList</em> to notify that this component is dirty and it has to be redrawn. </p>
<p>At the right time, the framework will attempt to refresh every “dirty” component by calling the <em>updateDisplayList</em> Method. We will add all the graphical logic here. In this example, we just iterate the points and draw lines between them. Note that a lot of optimizations could be added to this code but its easier to understand keeping it simple. </p>
<p>Now we will create a test Flex Application for this component to see it running: </p>
<pre class="syntax-highlight:xml">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;
		horizontalAlign=&quot;center&quot; verticalAlign=&quot;middle&quot; xmlns:comp=&quot;comp.*&quot;&gt;
	&lt;comp:BlackboardShape id=&quot;shape&quot; width=&quot;200&quot; height=&quot;200&quot;/&gt;
	&lt;mx:Button label=&quot;Draw!&quot; click=&quot;shape.addPoint(Math.random() * 200, Math.random()*200)&quot;/&gt;
&lt;/mx:Application&gt;</pre>
<p>It should work like this:</p>
<p>
<object type="application/x-shockwave-flash" width="400" height="400">
<param name="movie" value="http://www.carlosrovira.com/teamblog/wp-content/uploads/2008/09/components1.swf" />
<embed src="http://www.carlosrovira.com/teamblog/wp-content/uploads/2008/09/components1.swf" type="application/x-shockwave-flash" width="400" height="400" >
</object>
</p>
<p><br/></p>
<p>In my next post, I will show you the <em>Blackboard</em> component.</p>]]></content:encoded>
			<wfw:commentRss>http://www.carlosrovira.com/teamblog/2008/09/11/flex-component-architecture-by-example-i/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Welcome to the Team Blog!</title>
		<link>http://www.carlosrovira.com/teamblog/2008/09/01/hello-world/</link>
		<comments>http://www.carlosrovira.com/teamblog/2008/09/01/hello-world/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 00:00:38 +0000</pubDate>
		<dc:creator>Carlos Rovira</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.carlosrovira.com/teamblog/?p=1</guid>
		<description><![CDATA[Welcome to this new blog where consultants at carlosrovira.com will share his experiences with differents technologies.
We are focused mainly on RIAs build with the Flash Platform and JEE backends. Of course, we will write about Flash, Flex and Java, but we want not limit our post and will share all things we consider helpful and [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to this new blog where consultants at <a href="http://www.carlosrovira.com">carlosrovira.com</a> will share his experiences with differents technologies.</p>
<p>We are focused mainly on RIAs build with the Flash Platform and JEE backends. Of course, we will write about Flash, Flex and Java, but we want not limit our post and will share all things we consider helpful and interesting (maybe Linux?, PHP?, Rails?). We will talk here about our upcoming own technology that we are finishing in this days called <strong>RIAlity</strong>.</p>
<p>This blog will be written in English (opposite to <a href="http://www.carlosrovira.com/blog">my classic spanish blog</a>) and hope we&#8217;ll update this space with regularity.</p>
<p>With this blog, I hope you&#8217;ll find some gems written by talented people within our studio that has many things to share with the community.</p>
<p>Thanks for reading and hope you&#8217;ll think in <a href="http://www.carlosrovira.com/teamblog/feed/">syndicate our feed</a> in your favourite RSS reader.</p>
<p>Best,</p>
<p>Carlos Rovira.</p>]]></content:encoded>
			<wfw:commentRss>http://www.carlosrovira.com/teamblog/2008/09/01/hello-world/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
