<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lambda &#187; Papervision</title>
	<atom:link href="http://sroucheray.org/blog/tag/papervision/feed/" rel="self" type="application/rss+xml" />
	<link>http://sroucheray.org/blog</link>
	<description>Stephane Roucheray's trivial work and thoughts</description>
	<lastBuildDate>Mon, 23 Aug 2010 08:13:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Papervision : Mouse interaction with 2D MovieMaterial</title>
		<link>http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/</link>
		<comments>http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 13:01:55 +0000</pubDate>
		<dc:creator>Stéphane Roucheray</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Papervision]]></category>
		<category><![CDATA[MovieMaterial]]></category>
		<category><![CDATA[Papervision3D]]></category>

		<guid isPermaLink="false">http://sroucheray.org/blog/?p=508</guid>
		<description><![CDATA[The nature of Papervision MovieMaterial gives users the ability to interact with it's content. However it can be tricky to make it work.]]></description>
			<content:encoded><![CDATA[<a href="http://blog.papervision3d.org/">Papervision</a> lets apply textures as MovieClip on 3D object surfaces. This kind of textures is called <a href="http://papervision3d.googlecode.com/svn/trunk/as3/trunk/docs/org/papervision3d/materials/MovieMaterial.html">MovieMaterial</a>. The nature of MovieMaterial gives users the ability to interact with it&#8217;s content. However it&#8217;s often tricky to make it works.

In the following example I applied a MovieMaterial to a <a href="http://papervision3d.googlecode.com/svn/trunk/as3/trunk/docs/org/papervision3d/objects/primitives/Cube.html">Cube</a> (wihout depth so it looks like a <a href="http://papervision3d.googlecode.com/svn/trunk/as3/trunk/docs/index.html?org/papervision3d/objects/primitives/Cube.html&#038;org/papervision3d/objects/primitives/class-list.html">PaperPlane</a>) :


    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="600" height="600">
      <param name="movie" value="http://sroucheray.org/blog/wp-content/uploads/2009/11/moviematerial-interaction.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://sroucheray.org/blog/wp-content/uploads/2009/11/moviematerial-interaction.swf" width="600" height="600">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>


The button and TextField are both children of the MovieClip used as the material in the MovieMaterial. This example shows how the mouse can interact with the button. While it rotates along with the cube and its MovieMaterial, it handles well the three events : mouse over, mouse out and mouse click.

<h2>MouseClick on a button inside a MovieMaterial</h2>

MouseClick on a button is really easy to implement. A simple listener is added to the button Object :

<div class="codecolorer-container actionscript dawn nowrap" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">//WhitePanel class is an asset in the Fla's library</span><br />
panel = <span style="color: #000000; font-weight: bold;">new</span> WhitePanel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">//Set up the okButton inside the panel</span><br />
<span style="color: #000000; font-weight: bold;">var</span> okButton : <span style="color: #0066CC;">MovieClip</span> = <span style="color: #0066CC;">MovieClip</span><span style="color: #66cc66;">&#40;</span>panel.<span style="color: #006600;">okButton</span><span style="color: #66cc66;">&#41;</span>;<br />
okButton.<span style="color: #006600;">mouseChildren</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
okButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, clickListener<span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #000000; font-weight: bold;">var</span> okInc : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;<br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> clickListener <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp;++okInc;<br />
&nbsp;<span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span>panel.<span style="color: #006600;">title</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Click on OK Button : &quot;</span>+ okInc;<br />
<span style="color: #66cc66;">&#125;</span></div></div>

On button click the text field is well updated.

<h2>Mouse over and mouse out a sprite inside a MovieMaterial</h2>

The mouse over and mouse out events are a little bit more tricky to implement. In general, when a zone is interactive you want the mouse to change its aspects. When over it is transformed to a hand cursor and when out to the simple arrow cursor.
When working on a 2D stage it is done via these affectations :

<div class="codecolorer-container actionscript dawn nowrap" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">okButton.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
okButton.<span style="color: #0066CC;">useHandCursor</span>= <span style="color: #000000; font-weight: bold;">true</span>; <span style="color: #808080; font-style: italic;">//This is true by default</span></div></div>

Thus the hand cursor appears when over the okButton MovieClip. Unfortunately it doesn&#8217;t work with Papervision. The workaround is to affect handlers to the MovieClip and globally change the aspect of the mouse cursor :

<div class="codecolorer-container actionscript dawn nowrap" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">okButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_OVER</span>, handleOver<span style="color: #66cc66;">&#41;</span>;<br />
okButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_OUT</span>, handleOut<span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> handleOver<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//Globally change the mouse cursor aspect</span><br />
&nbsp; &nbsp; viewport.<span style="color: #006600;">containerSprite</span>.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//Not required, changes the aspect of the button</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//in our case</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">MovieClip</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">currentTarget</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #000000; font-weight: bold;">function</span> handleOut<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//Globally change the mouse cursor aspect</span><br />
&nbsp; &nbsp; viewport.<span style="color: #006600;">containerSprite</span>.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">MovieClip</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">currentTarget</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>

&#8212;

Download the demo sources <a href="http://sroucheray.org/blog/wp-content/plugins/download-monitor/download.php?id=1" title="Download MMInteractionDemo.zip">MMInteractionDemo.zip</a>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;title=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;title=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;t=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;title=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial&amp;summary=The%20nature%20of%20Papervision%20MovieMaterial%20gives%20users%20the%20ability%20to%20interact%20with%20it%27s%20content.%20However%20it%20can%20be%20tricky%20to%20make%20it%20work.&amp;source=Lambda" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;title=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;title=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial+-+http://bit.ly/bf6h8r&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/&amp;submitHeadline=Papervision+%3A+Mouse+interaction+with+2D+MovieMaterial&amp;submitSummary=The%20nature%20of%20Papervision%20MovieMaterial%20gives%20users%20the%20ability%20to%20interact%20with%20it%27s%20content.%20However%20it%20can%20be%20tricky%20to%20make%20it%20work.&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" class="external" title="Buzz up!">Buzz up!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://sroucheray.org/blog/2009/12/papervision-mouse-interaction-with-2d-moviematerial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

