<?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>franto.com &#187; Component</title>
	<atom:link href="http://franto.com/tag/component/feed/" rel="self" type="application/rss+xml" />
	<link>http://franto.com</link>
	<description></description>
	<lastBuildDate>Tue, 23 Aug 2011 10:29:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>FlexTip: Add Thumbs to Mx:Slider programatically</title>
		<link>http://franto.com/add-thumbs-to-mxslider-programatically/</link>
		<comments>http://franto.com/add-thumbs-to-mxslider-programatically/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 12:16:07 +0000</pubDate>
		<dc:creator>Franto</dc:creator>
				<category><![CDATA[Flex Tips]]></category>
		<category><![CDATA[Flexets]]></category>
		<category><![CDATA[Component]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.franto.com/?p=673</guid>
		<description><![CDATA[I have some new Flex Tip for you. Maybe you have found it already if you have tried add new thumbs to Mx:Slider (HSlider, VSlider) programatically. There can be various &#8220;small&#8221; problems. Or maybe there is just another way What I&#8217;ve tried is increase thumbCount property and add new value to values property. But there [...]]]></description>
			<content:encoded><![CDATA[<div class='series_toc'><h3>Table of contents for flex-tips</h3><ol><li><a href='http://franto.com/flextips/' title='FlexTips'>FlexTips</a></li><li><a href='http://franto.com/flextips-mxtext-vs-mxtextarea/' title='FlexTip: mx:Text vs. mx:TextArea'>FlexTip: mx:Text vs. mx:TextArea</a></li><li><a href='http://franto.com/flextips-xmlsocket-connect-after-disconnect-from-server/' title='FlexTip: XMLSocket connect() after disconnect from server'>FlexTip: XMLSocket connect() after disconnect from server</a></li><li><a href='http://franto.com/flextips-problem-with-masks-and-scalable-flash/' title='FlexTip: Problem with masks and scalable Flash'>FlexTip: Problem with masks and scalable Flash</a></li><li><a href='http://franto.com/flextips-how-to-add-bitmap-to-uicomponent/' title='FlexTips: How to add Bitmap to UIComponent'>FlexTips: How to add Bitmap to UIComponent</a></li><li><a href='http://franto.com/flextips-stop-displaying-focus/' title='FlexTip &#8211; Stop displaying Focus'>FlexTip &#8211; Stop displaying Focus</a></li><li><a href='http://franto.com/preventing-checkbox-selection-with-keyspace/' title='FlexTip: Preventing CheckBox selection with Key.SPACE'>FlexTip: Preventing CheckBox selection with Key.SPACE</a></li><li><a href='http://franto.com/flextip-wordwrap-for-mxtext/' title='FlexTip: WordWrap for mx:Text'>FlexTip: WordWrap for mx:Text</a></li><li>FlexTip: Add Thumbs to Mx:Slider programatically</li><li><a href='http://franto.com/as3-conditional-breakpoint-enterdebugger/' title='AS3 Conditional Breakpoint &#8211; enterDebugger()'>AS3 Conditional Breakpoint &#8211; enterDebugger()</a></li></ol></div> <div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;"><a href="http://twitter.com/share?url=http%3A%2F%2Ffranto.com%2Fadd-thumbs-to-mxslider-programatically%2F&amp;text=FlexTip: Add Thumbs to Mx:Slider programatically&amp;count=vertical&amp;lang=en&amp;related=Component,Flex,Flex+Tips"><img src="http://franto.com/blog2/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></a></div>
<p>I have some new Flex Tip for you. Maybe you have found it already if you have tried add new thumbs to Mx:Slider (HSlider, VSlider) programatically. There can be various &#8220;small&#8221; problems. Or maybe there is just another way <img src='http://franto.com/blog2/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>What I&#8217;ve tried is increase <strong>thumbCount</strong> property and add new value to <strong>values </strong>property. But there can be problems, if you did not set <strong>snapInterval</strong> property or how you insert new value.</p>
<p>I have created examples with 3 different ways of adding new thumbs to the horizontal slider. There can be more, but I want to show you just these 3 different way of how to do it.</p>
<p>In all examples sliders starting value as follows:</p>
<ul>
<li>minimum = 0</li>
<li>maximum = 0</li>
<li>thumbCount = 2</li>
<li>values = [0,1]</li>
</ul>
<p>I&#8217;m catching MouseEvent.CLICK event on these sliders, and add new thumb. After click you can check last added value, and values property of each slider for you control, what&#8217;s inside. Let&#8217;s try example and after I will explain difference in these 3 different ways fo adding new thumb to slider.</p>
<p><object id="SliderTest" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="600" height="450" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="quality" value="high" /><param name="bgcolor" value="#222222" /><param name="allowScriptAccess" value="sameDomain" /><param name="src" value="http://www.franto.com/blog2/wp-content/uploads/examples/slidertest/SliderTest.swf" /><param name="name" value="SliderTest" /><param name="align" value="middle" /><embed id="SliderTest" type="application/x-shockwave-flash" width="600" height="450" src="http://www.franto.com/blog2/wp-content/uploads/examples/slidertest/SliderTest.swf" align="middle" name="SliderTest" allowscriptaccess="sameDomain" bgcolor="#222222" quality="high"></embed></object></p>
<p>The first example I&#8217;m adding new value to the values property, which is Array by simple slider.values.push(newValue). Problem is that, when you push value e.g. 0.5 to array [0,1], values will be [0,1,0.5] it&#8217;s not sorted (slider has not sorted it by itself). It&#8217;s interesting how slider recompute it&#8217;s values. Just try it in example</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> handleAddWrongPoint<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> newValue<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = idWrongSlider.minimum <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">localX</span> <span style="color: #000000; font-weight: bold;">/</span> idWrongSlider.<span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span>idWrongSlider.maximum <span style="color: #000000; font-weight: bold;">-</span> idWrongSlider.minimum<span style="color: #000000;">&#41;</span>;
	newValue = <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span>newValue <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">100</span>;
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">target</span> <span style="color: #0033ff; font-weight: bold;">is</span> SliderThumb<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		latestWrong = newValue;
		idWrongSlider.thumbCount<span style="color: #000000; font-weight: bold;">++</span>;
		idWrongSlider.values.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>newValue<span style="color: #000000;">&#41;</span>;
		idWrongSlider.invalidateProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'Wrong: '</span> <span style="color: #000000; font-weight: bold;">+</span> e.<span style="color: #004993;">localX</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; , new: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> newValue <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; values: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> idWrongSlider.values<span style="color: #000000;">&#41;</span>;
&nbsp;
		update<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>In second example there is no snapInterval set, and it seems, that causes more interesting problems. Values are now greater than maximum (1), try add few thumbs by clicking on 2nd slider and you can end up with such values property [0,1,2,3,4,5,6,7,0.6]. Really don&#8217;t why <img src='http://franto.com/blog2/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> handleAddWrongPoint2<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> newValue<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = idWrongSlider2.minimum <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">localX</span> <span style="color: #000000; font-weight: bold;">/</span> idWrongSlider2.<span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span>idWrongSlider2.maximum <span style="color: #000000; font-weight: bold;">-</span> idWrongSlider2.minimum<span style="color: #000000;">&#41;</span>;
	newValue = <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span>newValue <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">100</span>;
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">target</span> <span style="color: #0033ff; font-weight: bold;">is</span> SliderThumb<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		latestWrong2 = newValue;
		idWrongSlider2.thumbCount<span style="color: #000000; font-weight: bold;">++</span>;
		idWrongSlider2.values.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>newValue<span style="color: #000000;">&#41;</span>;
		idWrongSlider2.invalidateProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'Wrong: '</span> <span style="color: #000000; font-weight: bold;">+</span> e.<span style="color: #004993;">localX</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; , new: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> newValue <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; values: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> idWrongSlider2.values<span style="color: #000000;">&#41;</span>;
&nbsp;
		update<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>In 3rd examples all is ok, because I&#8217;ve set snapInterval property to 0.01 and I&#8217;m adding new values correctly sorted</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> handleAddCorrectPoint<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> newValue<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = idCorrectSlider.minimum <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">localX</span> <span style="color: #000000; font-weight: bold;">/</span> idCorrectSlider.<span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span>idCorrectSlider.maximum <span style="color: #000000; font-weight: bold;">-</span> idCorrectSlider.minimum<span style="color: #000000;">&#41;</span>;
    newValue = <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span>newValue <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">100</span>;
    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">target</span> <span style="color: #0033ff; font-weight: bold;">is</span> SliderThumb<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        latestCorrect = newValue;
        idCorrectSlider.thumbCount<span style="color: #000000; font-weight: bold;">++</span>;
        <span style="color: #6699cc; font-weight: bold;">var</span> arr<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = idCorrectSlider.values;
        arr.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>newValue<span style="color: #000000;">&#41;</span>;
        idCorrectSlider.values = arr.<span style="color: #004993;">sort</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        idCorrectSlider.invalidateProperties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'Correct: '</span> <span style="color: #000000; font-weight: bold;">+</span> e.<span style="color: #004993;">localX</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; , new: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> newValue <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; values: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> idCorrectSlider.values<span style="color: #000000;">&#41;</span>;
        update<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Full source to this examples is included in <strong>Download Section</strong> (you will see it just as subscribed member) of our <strong><a href="http://www.flexets.com/forum-info/coaching-forum">Coaching Program</a> <a href="http://www.flexets.com/forum/">Forum</a></strong> on <a href="http://www.flexets.com">Flexets.com</a> (My own company).</p>
 <div class='series_links'><a href='http://franto.com/flextip-wordwrap-for-mxtext/' title='FlexTip: WordWrap for mx:Text'>Previous in series</a> <a href='http://franto.com/as3-conditional-breakpoint-enterdebugger/' title='AS3 Conditional Breakpoint &#8211; enterDebugger()'>Next in series</a></div>]]></content:encoded>
			<wfw:commentRss>http://franto.com/add-thumbs-to-mxslider-programatically/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

