<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.2" -->
<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/"
	>

<channel>
	<title>weka::blog</title>
	<link>http://blog.weka.com.br/en</link>
	<description>weka speaking about it's thoughts ;)</description>
	<pubDate>Wed, 09 Apr 2008 17:20:12 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.2</generator>
	<language>en</language>
			<item>
		<title>Flash and Mouse Wheel</title>
		<link>http://blog.weka.com.br/en/flash-and-mouse-wheel/</link>
		<comments>http://blog.weka.com.br/en/flash-and-mouse-wheel/#comments</comments>
		<pubDate>Mon, 03 Sep 2007 19:31:51 +0000</pubDate>
		<dc:creator>Saulo Brito</dc:creator>
		
		<category><![CDATA[issue]]></category>

		<category><![CDATA[as2]]></category>

		<category><![CDATA[as3]]></category>

		<category><![CDATA[scroll]]></category>

		<category><![CDATA[mouse]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[wheel]]></category>

		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://blog.weka.com.br/en/?p=3</guid>
		<description><![CDATA[The wheel button of our mouses is a prime. Everyone loves it. But how much Flash is wheel-friendly?
ActionScript 2
Flash allows the use of the mouse wheel button to scroll text fields. But not always. If you&#8217;re working in an AS2 project, your text field must be selectable to the wheel work properly over it. Otherwise [...]]]></description>
			<content:encoded><![CDATA[<p>The wheel button of our mouses is a prime. Everyone loves it. But how much Flash is wheel-friendly?</p>
<h3>ActionScript 2</h3>
<p>Flash allows the use of the mouse wheel button to scroll text fields. But not always. If you&#8217;re working in an AS2 project, your text field must be selectable to the wheel work properly over it. Otherwise you have to register a listener with Mouse class to help you do detect the wheel movement and act accordingly. It also will be the way if you want objects other than text fields to react to the &#8220;onMouseWheel&#8221; event.</p>
<p>Take a look at this example (<a href="http://blog.weka.com.br/en/simple-wheel-in-actionscript-2-code" title="Simple Wheel in AS2 Source">code</a>, <a href="http://blog.weka.com.br/en/wp-content/uploads/2007/09/simplewheel.zip" title="Simple wheel in AS2">project</a>):</p>

<object	type="application/x-shockwave-flash"
			data="http://blog.weka.com.br/en/wp-content/uploads/2007/09/simplewheel.swf"
			width="355"
			height="123">
	<param name="movie" value="http://blog.weka.com.br/en/wp-content/uploads/2007/09/simplewheel.swf" />
</object>
<p>This code seems to do the job but it brings some caveats:</p>
<ul>
<li>The SWF needs to be the focused object so it can capture the wheel event;</li>
<li>You have to click outside the object (at any point of the HTML page) to get back the browser wheel scrolling.</li>
</ul>
<p>Of course, that&#8217;s not the an expected behavior (for a non-flasher!) and, therefore, breaks the user experience.</p>
<h3> ActionScript 3</h3>
<p>Using AS3 can make your life a lot easier as non selectable texts can be scrolled normally and (probably because AS3 event bubbling mechanism) the browser scrolling get back to life when one of the edges of the scrolling text field is reached.</p>

<object	type="application/x-shockwave-flash"
			data="http://blog.weka.com.br/en/wp-content/uploads/2007/09/simplewheel-as3.swf"
			width="355"
			height="123">
	<param name="movie" value="http://blog.weka.com.br/en/wp-content/uploads/2007/09/simplewheel-as3.swf" />
</object>
<p>Download (<a href="http://blog.weka.com.br/en/simple-wheel-in-actionscript-3-code" title="Simple Wheel in AS3 Source">code</a>, <a href="http://blog.weka.com.br/en/wp-content/uploads/2007/09/simplewheel-as3.zip" title="Simple Wheel in AS3">project</a>).</p>
<p>Still, you have to click on the Flash object so it can capture the wheel event. Also, Flash can&#8217;t know if you want an InteractiveObject other than the TextField to respond to the wheel, so you have to do it programaticly. (Notice that you shouldn&#8217;t have both Flash and the browser responding that event).</p>
<h3>So what?</h3>
<p>Well&#8230; After some research, I&#8217;ve found <a href="http://adomas.org/javascript-mouse-wheel/" title="Mouse wheel programming in JavaScript">a JavaScript code</a> that help developers to create HTML controls which use the wheel button to deliver some functionality to the user. Mixing with some AS code it can help you to fix the usability issues explained early. In a few words:</p>
<ul>
<li>First, you have to setup the <a href="http://adomas.org/javascript-mouse-wheel/" title="Mouse wheel programming in JavaScript">Adomas&#8217;s solution</a> to detect the wheel event with JS and tell (through ExternalInterface) the Flash object when it happens;</li>
</ul>
<p>On the Flash side you normally will loop over an array of &#8220;wheelable&#8221; objects to see if some of them will react to the event (probably using hitTest/hitTestPoint).</p>
<ul>
<li>And then you tell the browser if it should prevent the scroll or not.</li>
</ul>
<p>I did two very simple examples using <a href="http://www.weka.com.br/t/flash/wheel/as2/jswheel.html" title="Javascript whell in AS2">AS2 </a>(<a href="http://blog.weka.com.br/en/wp-content/uploads/2007/09/jswheel.zip" title="Javascript whell in AS2">source</a>) and <a href="http://www.weka.com.br/t/flash/wheel/as3/jswheelas3.html" title="Javascript whell in AS3">AS3 </a>(<a href="http://blog.weka.com.br/en/wp-content/uploads/2007/09/jswheel-as3.zip" title="Javascript whell in AS3">source</a>).</p>
<p>Notice that you don&#8217;t need to click on flash object (the grayed area) and when there&#8217;s no more text to scroll, the browser scrolling works again!</p>
<h3>Conclusions</h3>
<p>To summarize, these are the scenarios that may lead you to use this solution:</p>
<h4>Using AS3</h4>
<ul>
<li> You want your scrolling object to work even if the flash object isn&#8217;t the focused object on the page;</li>
<li>You want to use mouse wheel to interact with objects other than text fields and prevent browser default behavior.</li>
</ul>
<h4>Using AS2</h4>
<ul>
<li>Same reasons above;</li>
<li>You want your non selectable text field to be wheel scrollable;</li>
</ul>
<h4>PS&#8217;s</h4>
<ul>
<li>The code was written trying to simplify things out. A real-world project probably would have more widgets that can be scrolled so is best (for you) define some classes to encapsulate the wheel functionality on each object. Would be nice to pack this idea into a &#8220;solution&#8221;. I&#8217;ll try to to this someday.</li>
</ul>
<ul>
<li>The code references _root (yeah, the evil one) a couple times  on it. Since hitTest use &#8220;global coordinate space&#8221; I think that, in this case, _root can be used without adding any weight on our shoulders.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.weka.com.br/en/flash-and-mouse-wheel/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
