<?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>FlexWiz Blog &#187; Components</title>
	<atom:link href="http://blog.flexwiz.net/category/flex/components/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexwiz.net</link>
	<description>On Game Development and the Flash platform</description>
	<lastBuildDate>Sat, 17 Dec 2011 22:46:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Efficient Gradient Box</title>
		<link>http://blog.flexwiz.net/efficient-gradient-box/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=efficient-gradient-box</link>
		<comments>http://blog.flexwiz.net/efficient-gradient-box/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 01:19:33 +0000</pubDate>
		<dc:creator>theWiz</dc:creator>
				<category><![CDATA[Components]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[Container]]></category>
		<category><![CDATA[Gradient]]></category>

		<guid isPermaLink="false">http://flexwiz.amosl.com/?p=87</guid>
		<description><![CDATA[The standard containers like Canvas, HBox, VBox offer only a solid color background. Occasionally you&#8217;d want to place a gradient as a background &#8211; now you can, using this custom component GradientCanvas. When often we are forced to use a bitmap as background (a very bad thing to do), the only viable alternative would be [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-135" title="Gradbox" src="http://blog.flexwiz.net/wp-content/uploads/2010/03/Gradbox.png" alt="" width="153" height="174" /><br />
The standard containers like Canvas, HBox, VBox offer only a solid color background. Occasionally you&#8217;d want to place a gradient as a background &#8211; now you can, using this custom component GradientCanvas.</p>
<p><span id="more-87"></span>
<p>When often we are forced to use a bitmap as background (a very bad thing to do), the only viable alternative would be to create the effect programmaticaly in the component code. Besides the obvious the advantage of saving memory, it allows us to resize the container without any side effects &#8211; making it a truly reusable component.</p>
<p><a href="http://blog.flexwiz.net/wp-content/uploads/2010/03/BoxApp.swf" target="_blank"><img class="alignnone size-full wp-image-145" style="margin-left: 36px; margin-right: 36px;" title="Gradbox_demo" src="http://blog.flexwiz.net/wp-content/uploads/2010/03/Gradbox_demo.png" alt="" width="132" height="60" /></a> <a href="http://blog.flexwiz.net/sources/gradbox/" target="_blank"><img class="size-full wp-image-111 alignnone" style="margin-left: 36px; margin-right: 36px;" title="getsource" src="http://blog.flexwiz.net/wp-content/uploads/2010/02/getsource.png" alt="" width="147" height="63" /></a></p>
<p>With the GradientCanvas properties its easy to control the colors, alphas and corners of the container &#8211;  up to 16 entries of colors and alphas can be used.<br />
The container code is a very basic example on how to create a custom container, and using it from mxml to achieve different effects.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;box:GradientCanvas</span> <span style="color: #000066;">top</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">left</span>=<span style="color: #ff0000;">&quot;290&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;190&quot;</span> <span style="color: #000066;">angle</span>=<span style="color: #ff0000;">&quot;75&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">colors</span>=<span style="color: #ff0000;">&quot;[0xffffe4 , 0xfff97f, 0xfff97f, 0xfff97f, 0xef8d23]&quot;</span>  <span style="color: #000066;">corners</span>=<span style="color: #ff0000;">&quot;[4,4,16,16]&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:VBox</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">top</span>=<span style="color: #ff0000;">&quot;16&quot;</span> <span style="color: #000066;">paddingLeft</span>=<span style="color: #ff0000;">&quot;16&quot;</span> <span style="color: #000066;">paddingRight</span>=<span style="color: #ff0000;">&quot;16&quot;</span> <span style="color: #000066;">horizontalAlign</span>=<span style="color: #ff0000;">&quot;center&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Label</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;While Supplies Last&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Press Me&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Text</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;{someText}&quot;</span>  <span style="color: #000066;">fontWeight</span>=<span style="color: #ff0000;">&quot;normal&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Spacer</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;22&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:VBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/box:GradientCanvas<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The code is compact, and most of the work is done inside the updateDisplayList function. Gradients can be created directly with the graphics drawing calls, but since we extent UIComponent its better to use the helper function that is already provided in the class.</p>
<p>This component can be further enhanced to leverage the functionality and create far more complex gradients, as much as needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexwiz.net/efficient-gradient-box/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A Simpler Button Scroll</title>
		<link>http://blog.flexwiz.net/a-simpler-button-scroll/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-simpler-button-scroll</link>
		<comments>http://blog.flexwiz.net/a-simpler-button-scroll/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 01:22:07 +0000</pubDate>
		<dc:creator>theWiz</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Components]]></category>
		<category><![CDATA[Button]]></category>
		<category><![CDATA[Container]]></category>
		<category><![CDATA[Tween]]></category>

		<guid isPermaLink="false">http://flexwiz.amosl.com/?p=93</guid>
		<description><![CDATA[For one of my projects, a client asked for vertical list with up/down buttons in place of scrollbars with smooth scrolling. I found a few classes that gave a partial solution, but some gave choppy results, and for others I didn’t like their long and complex code. After a lot of tryouts I came across [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-109" style="margin: 8px; border: 1px solid black;" src="http://blog.flexwiz.net/wp-content/uploads/2010/02/ScrollList.png" alt="" width="232" height="217" /><br />
For one of my projects, a client asked for vertical list with up/down buttons in place of scrollbars with smooth scrolling.<br />
I found a few classes that gave a partial solution, but some gave choppy results, and for others I didn’t like their long and complex code. After a lot of tryouts I came across <a href="http://dougmccune.com/blog/" target="_blank">Doug McCune’s</a> ButtonScrollingCanvas, which came close to what I needed.<br />
<span id="more-93"></span><br />
The <a href="http://flexlib.googlecode.com/svn/trunk/examples/DragCanvas_Sample.swf" target="_blank">ButtonScrollingCanvas</a> container is one of many flex controls in the excellent open source <a href="http://flexlib.net/" target="_blank">flexlib </a>library – a must for any serious flex developer. It is a container component that uses buttons placed over the edges of the container to do the scrolling of its children, and the buttons can be fully skinned.</p>
<p>Inspired by the flexlib code, I decided to write my own container based on the same ideas, only with a slightly different implementation.</p>
<p style="padding-left: 60px;"><a href="http://blog.flexwiz.net/sources/btsdemo/ScrollDemoApp.swf" target="_blank"><br />
<img style="margin-left: 20px; margin-right: 20px;" src="http://blog.flexwiz.net/wp-content/uploads/2010/02/ScrollListDemo2.png" alt="" width="130" height="90" /></a> <a href="http://blog.flexwiz.net/sources/btnscroll/" target="_blank"><img class="alignnone size-full wp-image-111" style="margin-left: 20px; margin-right: 20px;" src="http://blog.flexwiz.net/wp-content/uploads/2010/02/getsource.png" alt="" width="210" height="90" /></a></p>
<p>This resulted in ButtonScrollLite, a container suitable for games and touch displays, where you just tap the arrows to flip through content of any kind.  Its simple to use &#8211; just place any child elements inside it in the mxml and it works right out of the box. The arrow buttons are fully sinkable, so anyone can decide to roll their own buttons.</p>
<p>Properties:</p>
<ul>
<li>direction  &#8211; (horizontal|vertical) default is vertical</li>
<li>scrollSize  &#8211; the size (in pixels) to scroll in a single step- default is 10. Typically you want to set it to the size of one item in your list, although they can be in different sizes.</li>
</ul>
<p>The bulk of the code is in 2 functions: createChildren and updateDisplayList.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"> override protected <span style="color: #000000; font-weight: bold;">function</span> createChildren<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0066CC;">super</span>.<span style="color: #006600;">createChildren</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #808080; font-style: italic;">// We have 4 buttons for each side of the conainter</span>
	    	leftButton = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		rightButton = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		upButton = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		downButton = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		leftButton.<span style="color: #006600;">styleName</span> = <span style="color: #0066CC;">getStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;leftButtonStyleName&quot;</span><span style="color: #66cc66;">&#41;</span>;
		rightButton.<span style="color: #006600;">styleName</span> = <span style="color: #0066CC;">getStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;rightButtonStyleName&quot;</span><span style="color: #66cc66;">&#41;</span>;
		upButton.<span style="color: #006600;">styleName</span> = <span style="color: #0066CC;">getStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;upButtonStyleName&quot;</span><span style="color: #66cc66;">&#41;</span>;
		downButton.<span style="color: #006600;">styleName</span> = <span style="color: #0066CC;">getStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;downButtonStyleName&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">// this is the main canvas component, we tell it to</span>
		<span style="color: #808080; font-style: italic;">// never show the scrollbars since we're controlling them</span>
		<span style="color: #808080; font-style: italic;">// on our own</span>
		innerCanvas = <span style="color: #000000; font-weight: bold;">new</span> Canvas<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		innerCanvas.<span style="color: #006600;">document</span> = <span style="color: #0066CC;">this</span>.<span style="color: #006600;">document</span>;
		innerCanvas.<span style="color: #006600;">horizontalScrollPolicy</span> = ScrollPolicy.<span style="color: #006600;">OFF</span>;
		innerCanvas.<span style="color: #006600;">verticalScrollPolicy</span> = ScrollPolicy.<span style="color: #006600;">OFF</span>;
&nbsp;
		...
	<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>First, createChildren sets up the four buttons and their styles (so they are skinnable). It also creates the inner canvas, that will hold the actual contents, and turns off the scroll policy so that no scrollbars will show.</p>
<p>All the rest is handled in updateDisplayList:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">    override protected <span style="color: #000000; font-weight: bold;">function</span> updateDisplayList<span style="color: #66cc66;">&#40;</span>unscaledWidth:<span style="color: #0066CC;">Number</span>, unscaledHeight:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0066CC;">super</span>.<span style="color: #006600;">updateDisplayList</span><span style="color: #66cc66;">&#40;</span>unscaledWidth,unscaledHeight<span style="color: #66cc66;">&#41;</span>;
&nbsp;
            ...
            <span style="color: #000000; font-weight: bold;">var</span> btnSpace:<span style="color: #0066CC;">Number</span> = btnHeight + _buttonGap;
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_direction == VERTICAL<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            	innerCanvas.<span style="color: #006600;">setActualSize</span><span style="color: #66cc66;">&#40;</span>unscaledWidth,
            	            	      unscaledHeight - btnSpace<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;
            	innerCanvas.<span style="color: #006600;">move</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, btnSpace<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
            <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
            	btnSpace = btnWidth + _buttonGap;
            	innerCanvas.<span style="color: #006600;">setActualSize</span><span style="color: #66cc66;">&#40;</span>unscaledWidth - btnSpace<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">2</span>,
            	            	     unscaledHeight<span style="color: #66cc66;">&#41;</span>;
            	innerCanvas.<span style="color: #006600;">move</span><span style="color: #66cc66;">&#40;</span>btnSpace, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
	    positionButtons<span style="color: #66cc66;">&#40;</span>unscaledWidth, unscaledHeight<span style="color: #66cc66;">&#41;</span>;
            callLater<span style="color: #66cc66;">&#40;</span>enableOrDisableButtons<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The buttons and inner canvas are sized and placed in their position, depending on the layout direction (vertical or horizontal).</p>
<p>To perform the smooth scroll, I used a tweener (Greensock TweenLite) – this saved me the need to use timer events or enter frame, and the easing function gives it a more natural motion.</p>
<p>Feel free to use the class in any apps,  modify it , or use new skins.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexwiz.net/a-simpler-button-scroll/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

