<?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>Fightskillz.com &#187; Code</title>
	<atom:link href="http://fightskillz.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://fightskillz.com</link>
	<description>Life, Code, &#38; Idiocy</description>
	<lastBuildDate>Sat, 14 Aug 2010 00:54:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Weird Flex Error #2006</title>
		<link>http://fightskillz.com/2010/07/weird-flex-error-2006/</link>
		<comments>http://fightskillz.com/2010/07/weird-flex-error-2006/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 15:31:20 +0000</pubDate>
		<dc:creator>Yoav Givati</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[error #2006]]></category>
		<category><![CDATA[firstChild]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[lastChild]]></category>
		<category><![CDATA[mxml]]></category>
		<category><![CDATA[removedEffect]]></category>
		<category><![CDATA[States]]></category>

		<guid isPermaLink="false">http://fightskillz.com/?p=2167</guid>
		<description><![CDATA[I was getting this weird error whenever switching from a given state to it's parent state in a Flex 3.5 based project.
RangeError: Error #2006: The supplied index is out of bounds.
	at flash.display::DisplayObjectContainer/addChildAt()
	at mx.core::Container/addChildAt()
	at mx.effects::EffectManager$/removedEffectHandler()
	at Function/http://adobe.com/AS3/2006/builtin::apply()
	at mx.core::UIComponent/callLaterDispatcher2()
	at mx.core::UIComponent/callLaterDispatcher()
It threw me for a minute because I hadn't made any changes to effects since I last tested the [...]]]></description>
			<content:encoded><![CDATA[<p>I was getting this weird error whenever switching from a given state to it's parent state in a Flex 3.5 based project.</p>
<pre>RangeError: Error #2006: The supplied index is out of bounds.
	at flash.display::DisplayObjectContainer/addChildAt()
	at mx.core::Container/addChildAt()
	at mx.effects::EffectManager$/removedEffectHandler()
	at Function/http://adobe.com/AS3/2006/builtin::apply()
	at mx.core::UIComponent/callLaterDispatcher2()
	at mx.core::UIComponent/callLaterDispatcher()</pre>
<p>It threw me for a minute because I hadn't made any changes to effects since I last tested the application and I couldn't see any connection between the code I had just written and any effects in the app. But after hunting around I found the culprit. There's a set of components in a Canvas that gets removed when moving to the parent state. What I had done was separate those components into two Canvases(Canvi?). For whatever crazy reason the new second Canvas can't have a RemoveEffect. The code works fine if just the first Canvas has it, but if both or just the second Canvas has it then it throws that error.</p>
<p><em>side note: the reason it took me a while to find the source of the error was because I copy/pasted the canvas declaration only changing the id, and I forgot that there was a removedEffect associated with it.</em></p>
<p><strong>But wait there's more</strong>. The reason I split the components into two distinct Canvases was so I could position one below and the other on top of a third major component in z-space. The solution was to add the first Canvas as a "firstChild" and the second Canvas as a "lastChild". That it seems was the problem. In mxml when changing states you apparently can't add a firstChild before adding a lastChild. so I copy and pasted the first Canvas below the second one, so that all the lastChild additions occurred before all the firstChild additions and voila, presto, it works.</p>
<p>The reason is that when you move from a state back to its parent state it follows the order in which you add components in the state declaration to remove them. If the first component you add is added as a firstChild then that <strong>get's removed first changing the indexes and number of children of the parent container</strong>. I guess the underlying state changing function already calculated what the lastChild index was, so when trying to remove a Child with the pre-calculated index of lastChild it triggered an index out of bounds error.</p>
]]></content:encoded>
			<wfw:commentRss>http://fightskillz.com/2010/07/weird-flex-error-2006/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex Skins, Registration Points, and Illustrator CS5</title>
		<link>http://fightskillz.com/2010/05/flex-skins-registration-points-and-illustrator-cs5/</link>
		<comments>http://fightskillz.com/2010/05/flex-skins-registration-points-and-illustrator-cs5/#comments</comments>
		<pubDate>Fri, 14 May 2010 11:37:08 +0000</pubDate>
		<dc:creator>Yoav Givati</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Other Idiots]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[9-slice]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[CS4]]></category>
		<category><![CDATA[CS5]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[Flex 3 Skin]]></category>
		<category><![CDATA[Illustrator]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[registration point]]></category>
		<category><![CDATA[skinning]]></category>
		<category><![CDATA[upgrade]]></category>

		<guid isPermaLink="false">http://fightskillz.com/?p=2140</guid>
		<description><![CDATA[In Illustrator CS4 it was really easy to make Flex Skins. You just go to File -&#62; Scripts -&#62; Flex Skins -&#62; Create Flex 3 Skin, choose the components you want to skin - optionally give it a style class name, style it, use the same menu to export for Flex, use the Flex Builder [...]]]></description>
			<content:encoded><![CDATA[<p>In Illustrator CS4 it was really easy to make Flex Skins. You just go to <strong>File -&gt; Scripts -&gt; Flex Skins -&gt; Create Flex 3 Skin</strong>, choose the components you want to skin - optionally give it a style class name, style it, use the same menu to export for Flex, use the Flex Builder skin import feature which creates or adds to your CSS file and blah blah blah. If you want me to do a tutorial on that just comment and ask.</p>
<p style="text-align: center;"><a href="http://fightskillz.com/files/2010/05/newsymbol.png" rel="shadowbox[post-2140];player=img;"><img class="size-full wp-image-2144 aligncenter" title="alert" src="http://fightskillz.com/files/2010/05/alert.png" alt="" width="476" height="213" /><br /></a></p>
<p>In Illustrator CS5 they've updated the way registration points work. Flex 3(halo) skins require that the registration points be in the top left of the symbol. Illustrator CS5 defaults to a center registration point, so when you open your CS4 Illustrator skin file in CS5, it updates the registration point mechanism and defaults all your registration points to the center. Don't hulk-smash your computer just yet.</p>
<p>Another key difference with CS5 is while you get finer registration point control, it takes more work to move the registration point after the symbol is created. Say you've opened your CS4 created Flex 3 skin in CS5 and your registration points have been centered. There are a bunch of ways to edit the symbol. You could double click on the the symbol instance, or the symbol in the symbol pane, or click <strong>Edit Symbol</strong> at the top. Once editing the symbol, you'd need to drag your symbol around - make sure you get all the layers - positioning<em> it</em> rather than the registration point and don't forget to move the 9-slice guides. This process get's messy fast, it's time consuming, and it'll be hard to get the registration point and guides exactly where you want/need them. It's aggravating that there isn't a faster way to do it, and that in converting the file to work with CS5 it doesn't keep the registration point locations. So if you know a better faster way let me know. Until then here's the fastest way I've found to move all your registration points back to the top left.</p>
<ol>
<li>First <strong>Save as </strong>your skin file, you can use the same filename but will get a dialog to save it as a CS5 compatible file</li>
<li>Click on the symbol instance, ie: the Up skin for a button, make sure you've got it selected on the artboard</li>
<li>Click on the <strong>Symbol Options button </strong>in the Symbol pane</li>
<li>Copy the name to the clipboard (ctrl/option + c)</li>
<li>Click <strong>Cancel</strong></li>
<li>Click the <strong>Break Link button</strong> in the Symbol pane</li>
<li>Make sure the correct symbol is still selected in the Symbol pane, the selection may have jumped to the top left symbol in the list</li>
<li>Click on the <strong>Delete Symbol button</strong> in the Symbol pane</li>
<li>Delete the symbol, if it tells you there are other instances then take special care and double check that the correct symbol is selected; due to the nature of a flex 3 skin there should only be one instance of each symbol. It's not impossible to have multiple instances, but you would know if you created them.</li>
<li>Click on the <strong>New Symbol button</strong> in the Symbol pane</li>
<li>Paste the name you have in the clipboard (ctrl/option + v)</li>
<li>Select the <strong>top left corner</strong> for the registration point</li>
<li>Tick the box for <strong>Enable Guides for 9-Slice Scaling</strong></li>
<li>Click Ok, and repeat for every other symbol</li>
<li>Now you can save, backup with <a href="https://www.dropbox.com/referrals/NTUyNjUyNDA5">DropBox</a>, export as a Flex 3 skin, and finally it's time...</li>
<li>Hulk-SMASH!!! SMASH! this really should have been automated in the import mechanism.. right?</li>
</ol>
<p>&nbsp;</p>
<p style="text-align: center;"><a href="http://fightskillz.com/files/2010/05/break_link.png" rel="shadowbox[post-2140];player=img;"><img class="size-medium wp-image-2142 aligncenter" title="break_link" src="http://fightskillz.com/files/2010/05/break_link-300x162.png" alt="" width="300" height="162" /></a></p>
<p style="text-align: center;">click image to zoom</p>
<p style="text-align: center;"><img class="size-full wp-image-2143 aligncenter" title="newsymbol" src="http://fightskillz.com/files/2010/05/newsymbol.png" alt="" width="423" height="209" /></p>
]]></content:encoded>
			<wfw:commentRss>http://fightskillz.com/2010/05/flex-skins-registration-points-and-illustrator-cs5/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Adobe Flex/Air Bug &#8211; Serving Content via PHP</title>
		<link>http://fightskillz.com/2010/02/adobe-flexair-bug-serving-content-via-php/</link>
		<comments>http://fightskillz.com/2010/02/adobe-flexair-bug-serving-content-via-php/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 22:49:50 +0000</pubDate>
		<dc:creator>Yoav Givati</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[gateway]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[not working]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sound]]></category>
		<category><![CDATA[streaming]]></category>
		<category><![CDATA[urlrequest]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://fightskillz.com/?p=1909</guid>
		<description><![CDATA[I've been using a php script as a gateway to fetching certain content from a server, mainly mp3 files. There are a bunch of reasons for doing this, the main ones would be to be able to easily log which files are being accessed, when, and by who - and if you plan on creating [...]]]></description>
			<content:encoded><![CDATA[<p>I've been using a php script as a gateway to fetching certain content from a server, mainly mp3 files. There are a bunch of reasons for doing this, the main ones would be to be able to easily log which files are being accessed, when, and by who - and if you plan on creating widgets for your users to stream the content they upload to your site and they happen to put it on a heavily visited part of the web you can temporarily disable or limit that user's widget's access to content giving your other user's priority and preventing your server from crashing or being overworked.</p>
<p>So in the Flex/AIR app I've got a URLRequest that's used to load a Sound object. Instead of specifying the index.php it had been accessing <strong>http://domain.com?var1=blah&amp;var2=blah</strong>. Usually this will redirect to the index.php sending it the post variables and letting it do it's thing and fetch the mp3. It works on Adobe AIR for Mac, it works in a browser on Mac/Windows. But in a URLRequest from Windows it doesn't work, confirmed for XP and 7. It doesn't just redirect to the /index.php file and drop the POST/GET variables, it actually just doesn't redirect anywhere, and you get an IOError. You'd think the redirect would be handled entirely by the server and transparent to the client, but it appears that for whatever reason, Adobe AIR on Windows just returns an IO Error.</p>
<p>Either way it's easy to fix, you just have to specify the index file in your URLRequest like so: <strong>http://domain.com/index.php?var1=blah&amp;var2=blah</strong>.<strong> </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://fightskillz.com/2010/02/adobe-flexair-bug-serving-content-via-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex/Actionscript 3.0 Strip HTML Tags Function</title>
		<link>http://fightskillz.com/2010/01/flexactionscript-3-0-strip-html-tags-function/</link>
		<comments>http://fightskillz.com/2010/01/flexactionscript-3-0-strip-html-tags-function/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 19:59:59 +0000</pubDate>
		<dc:creator>Yoav Givati</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flex stript_tags]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[remove]]></category>
		<category><![CDATA[strip tags]]></category>

		<guid isPermaLink="false">http://fightskillz.com/?p=1802</guid>
		<description><![CDATA[I needed a function to strip out html tags from a text input, but still let me specify allowable tags.
Instead of spending time figuring out the regular expressions needed to pull it off and becoming a better programmer, I figured why repeat work someone else has probably already done.. I mean I could be a [...]]]></description>
			<content:encoded><![CDATA[<p>I needed a function to strip out html tags from a text input, but still let me specify allowable tags.</p>
<p>Instead of spending time figuring out the regular expressions needed to pull it off and becoming a better programmer, I figured why repeat work someone else has probably already done.. I mean I could be a busy man. Anyway I found this great function on Flexer.info [<a href="http://www.flexer.info/2008/04/08/strip-html-tags-with-allowable-tags/comment-page-1/#comment-1787">link</a>]. But after trying it out I noticed that the one tag I really really wanted to be parsed out <em>iframe</em> wasn't. It seems because I had specified <em>i </em>as an allowable tag it was also accepting <em>iframe</em>.</p>
<p>So with all due respect to Andrei, below is the revised function with the security hole patched.</p>
<p>All I changed was near the bottom where it determines if it's an allowable tag or not the reg exp was <i>
<pre><\/?" + tagsToKeep[j] + "[^<>]*?></i></pre>
<p> which allowed any character to follow the allowed tag as long as it wasn't a nested tag, which included <i>frame</i> following <i>i</i>. This will also support self closing tags.</p>
<pre class="actionscript">&nbsp;
<span style="color: #808080; font-style: italic;">// strips htmltags</span>
<span style="color: #808080; font-style: italic;">// @param html - string to parse</span>
<span style="color: #808080; font-style: italic;">// @param tags - tags to ignore</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> stripHtmlTags<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">html</span>:<span style="color: #0066CC;">String</span>, tags:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> tagsToBeKept:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>tags.<span style="color: #0066CC;">length</span> &gt; <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
        tagsToBeKept = tags.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> RegExp<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>s*,<span style="color: #000099; font-weight: bold;">\\</span>s*&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">var</span> tagsToKeep:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i &lt; tagsToBeKept.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>tagsToBeKept<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> != <span style="color: #000000; font-weight: bold;">null</span> &amp;&amp; tagsToBeKept<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> != <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span>
            tagsToKeep.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>tagsToBeKept<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">var</span> toBeRemoved:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000000; font-weight: bold;">var</span> tagRegExp:RegExp = <span style="color: #000000; font-weight: bold;">new</span> RegExp<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;&lt;([^&gt;<span style="color: #000099; font-weight: bold;">\\</span>s]+)(<span style="color: #000099; font-weight: bold;">\\</span>s[^&gt;]+)*&gt;&quot;</span>, <span style="color: #ff0000;">&quot;g&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">var</span> foundedStrings:<span style="color: #0066CC;">Array</span> = <span style="color: #0066CC;">html</span>.<span style="color: #006600;">match</span><span style="color: #66cc66;">&#40;</span>tagRegExp<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span>i = <span style="color: #cc66cc;">0</span>; i &lt; foundedStrings.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">var</span> tagFlag:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>tagsToKeep != <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> j:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; j &lt; tagsToKeep.<span style="color: #0066CC;">length</span>; j++<span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">var</span> tmpRegExp:RegExp = <span style="color: #000000; font-weight: bold;">new</span> RegExp<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;&lt;<span style="color: #000099; font-weight: bold;">\/</span>?&quot;</span> + tagsToKeep<span style="color: #66cc66;">&#91;</span>j<span style="color: #66cc66;">&#93;</span> + <span style="color: #ff0000;">&quot; ?/?&gt;&quot;</span>, <span style="color: #ff0000;">&quot;i&quot;</span><span style="color: #66cc66;">&#41;</span>;
                <span style="color: #000000; font-weight: bold;">var</span> tmpStr:<span style="color: #0066CC;">String</span> = foundedStrings<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> as <span style="color: #0066CC;">String</span>;
                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>tmpStr.<span style="color: #006600;">search</span><span style="color: #66cc66;">&#40;</span>tmpRegExp<span style="color: #66cc66;">&#41;</span> != <span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span>
                    tagFlag = <span style="color: #000000; font-weight: bold;">true</span>;
            <span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!tagFlag<span style="color: #66cc66;">&#41;</span>
            toBeRemoved.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>foundedStrings<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span>i = <span style="color: #cc66cc;">0</span>; i &lt; toBeRemoved.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">var</span> tmpRE:RegExp = <span style="color: #000000; font-weight: bold;">new</span> RegExp<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;([<span style="color: #000099; font-weight: bold;">\+</span><span style="color: #000099; font-weight: bold;">\*</span><span style="color: #000099; font-weight: bold;">\$</span><span style="color: #000099; font-weight: bold;">\/</span>])&quot;</span>,<span style="color: #ff0000;">&quot;g&quot;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #000000; font-weight: bold;">var</span> tmpRemRE:RegExp = <span style="color: #000000; font-weight: bold;">new</span> RegExp<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>toBeRemoved<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> as <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span>tmpRE, <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>$1&quot;</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #ff0000;">&quot;g&quot;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0066CC;">html</span> = <span style="color: #0066CC;">html</span>.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span>tmpRemRE, <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0066CC;">html</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://fightskillz.com/2010/01/flexactionscript-3-0-strip-html-tags-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Length is Semi-Reserved</title>
		<link>http://fightskillz.com/2009/11/length-is-semi-reserved/</link>
		<comments>http://fightskillz.com/2009/11/length-is-semi-reserved/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 14:46:58 +0000</pubDate>
		<dc:creator>Yoav Givati</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Idiocy]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://fightskillz.com/?p=1742</guid>
		<description><![CDATA[I'm writing a Flex/AIR app that grabs stuff from a database and displays it in an mx.controls.list. Interacting with it you can switch the list mode, which changes the visibility of certain controls in the itemRenderer. There are currently 20 items in the dataProvider, about 8 are displayed at any given time. I noticed that [...]]]></description>
			<content:encoded><![CDATA[<p>I'm writing a Flex/AIR app that grabs stuff from a database and displays it in an <strong>mx.controls.list</strong>. Interacting with it you can switch the list mode, which changes the visibility of certain controls in the <strong>itemRenderer</strong>. There are currently 20 items in the <strong>dataProvider</strong>, about 8 are displayed at any given time. I noticed that switching modes - and by doing so waiting for <strong>validateList()</strong> to run, took incrementally larger amounts of time for each of the first 3 items that were in view. So if you scrolled down one item and switched modes it was a bit faster, and if you scrolled past the first 3 switching modes became instant as it should be.</p>
<p>After looking over the same possibly relevant lines of code several times, reading up in detail of how the <strong>validateList()</strong> cycle works and getting into the nitty gritty of list classes I realized the problem was on the database side. I had a column named <em><strong>length</strong></em>. At first I thought there was an issue where I'd set the column type as a floating point number and maybe actionscript was having a time converting it or dealing with it in an object - there's no actual reason why I thought this, but the performance issue was not noticeable if the floating point number was smaller than 10,000.</p>
<p>Fortunately after only a few hours time wasted I, the spaz writing this, realized that the <em><strong>length</strong></em> column was being interpreted in actionscript as the <em><strong>length</strong></em>(ie: number of children/values) of the object. So say length was set to 100,000, for every item in the list it would have to create and analyze 999,992 blank values - creating space in memory for each one, along with the 8 actual values pulled from the database.</p>
<p>Furthermore when I referenced the <strong>item.length</strong> value while technically the value pulled from the database, was really the number of children in the object. The small robots that live inside my computer and make it work must have though I was bananas.</p>
<p>I'd like this to be my formal application for the prestigious <strong>Leader of the Idiots</strong>, but since I'm obviously not equipped with the basic skill set to do anything(read: dressing oneself, remembering reserved names) I'll rely on some kind soul reading this to file the application for me and submit it to the proper authorities.. thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://fightskillz.com/2009/11/length-is-semi-reserved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex: Variables, Anonymous Functions, and For Loops</title>
		<link>http://fightskillz.com/2009/09/flex-variables-anonymous-functions-and-for-loops/</link>
		<comments>http://fightskillz.com/2009/09/flex-variables-anonymous-functions-and-for-loops/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 06:38:36 +0000</pubDate>
		<dc:creator>Yoav Givati</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Flex 3.4]]></category>
		<category><![CDATA[Google Maps]]></category>

		<guid isPermaLink="false">http://fightskillz.com/?p=1532</guid>
		<description><![CDATA[I just ran into some weird behaviour involving a for loop, some variables, and a bunch of anonymous functions. This is in Actionscript 3.0 using Flex SDK 3.4 and current Google Maps API(as of the date of this post&#038;mdash I read somewhere they're rolling out a new version although it's not really relevant for this [...]]]></description>
			<content:encoded><![CDATA[<p>I just ran into some weird behaviour involving a for loop, some variables, and a bunch of anonymous functions. This is in Actionscript 3.0 using Flex SDK 3.4 and current Google Maps API(as of the date of this post&mdash I read somewhere they're rolling out a new version although it's not really relevant for this post) </p>
<p>So below I have a function that loops through the xml result of an http service, for each item in the result it creates a marker on a map and gives that marker a click event. When you click on a given marker I want a window to pop up with the name and description of that location, so the following is the code you'd expect to write. For simplicity sake you can keep an eye on the <b>i:int</b> variable which will help clarify the issue.</p>
<pre class="actionscript">&nbsp;
<span style="color: #808080; font-style: italic;">//trace(i) will always output total items in the xml result</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> processResult<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> total:<span style="color: #0066CC;">int</span> = event.<span style="color: #006600;">result</span>.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">item</span>.<span style="color: #0066CC;">length</span>;
&nbsp;
  <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i&lt;total; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> item:<span style="color: #0066CC;">Object</span> = event.<span style="color: #006600;">result</span>.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">item</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
    <span style="color: #808080; font-style: italic;">//this will create the marker object</span>
    <span style="color: #000000; font-weight: bold;">var</span> marker = <span style="color: #000000; font-weight: bold;">new</span> Marker<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> LatLng<span style="color: #66cc66;">&#40;</span>item.<span style="color: #006600;">lat</span>, item.<span style="color: #006600;">lng</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> MarkerOptions<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>fillStyle: <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">color</span>: 0xEE9C21<span style="color: #66cc66;">&#125;</span>, radius: <span style="color: #cc66cc;">7</span>, tooltip: item.<span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    marker.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MapMouseEvent.<span style="color: #006600;">CLICK</span>, <span style="color: #000000; font-weight: bold;">function</span><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: #808080; font-style: italic;">//this will open an info window when the marker is clicked</span>
      map.<span style="color: #006600;">openInfoWindow</span><span style="color: #66cc66;">&#40;</span>map.<span style="color: #006600;">getCenter</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> InfoWindowOptions<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>hasTail: <span style="color: #000000; font-weight: bold;">true</span>, tailHeight: <span style="color: #cc66cc;">5</span>, hasShadow: <span style="color: #000000; font-weight: bold;">true</span>, title:item.<span style="color: #0066CC;">name</span>, contentHTML:item.<span style="color: #006600;">description</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;
    	<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
  map.<span style="color: #006600;">addOverlay</span><span style="color: #66cc66;">&#40;</span>marker<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>Now what you'll find with the above code is that no matter which placemark you click on, they will all show the same name and description. Say that there are 5 items in the xml result, tracing <b>i</b> will output the number 5. </p>
<p><small><i>If you're new to programming, yes <b>i</b> will be 0 during the for loop's first run. Yes having 5 items and starting at 0 means it should be 4 for the last run, but the value of <b>i</b> increments one last time to make the <b>i&lt;total</b> condition false before it exits the loop, so essentially it uses the final value of <b>i</b> for all the placemarks which is 5.</i></small></p>
<p> I can't see any reason why this should be happening other than language or framework immaturity.</p>
<p>The solution; or I should say the easiest, quickest solution, is to create an external function for marker creation that is called by the for loop, which for clarity's sake will only contain the part that's required to explain the concept and make it work ie: adding an event listener to the marker, but in the real world should have all the code necessary for creating a marker - that way you'd have an independent marker creation function you could call from anywhere in the application. Below is the working code:</p>
<pre class="actionscript">&nbsp;
<span style="color: #808080; font-style: italic;">//trace(i) will output the correct index depending on the placemark clicked</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> processResult<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> total:<span style="color: #0066CC;">int</span> = event.<span style="color: #006600;">result</span>.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">item</span>.<span style="color: #0066CC;">length</span>;
&nbsp;
  <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i&lt;total; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">var</span> item:<span style="color: #0066CC;">Object</span> = event.<span style="color: #006600;">result</span>.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">item</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
    <span style="color: #000000; font-weight: bold;">var</span> marker = <span style="color: #000000; font-weight: bold;">new</span> Marker<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> LatLng<span style="color: #66cc66;">&#40;</span>item.<span style="color: #006600;">lat</span>, item.<span style="color: #006600;">lng</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> MarkerOptions<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>fillStyle: <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">color</span>: 0xEE9C21<span style="color: #66cc66;">&#125;</span>, radius: <span style="color: #cc66cc;">7</span>, tooltip: item.<span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">//call external function and pass variables to it</span>
    placeMarkerAddClickEventListener<span style="color: #66cc66;">&#40;</span>marker, item.<span style="color: #0066CC;">name</span>, item.<span style="color: #006600;">description</span><span style="color: #66cc66;">&#41;</span>;
    map.<span style="color: #006600;">addOverlay</span><span style="color: #66cc66;">&#40;</span>marker<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//external function</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> placeMarkerAddClickEventListener<span style="color: #66cc66;">&#40;</span>marker:Marker, <span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span>, description:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
  marker.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MapMouseEvent.<span style="color: #006600;">CLICK</span>, <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
    map.<span style="color: #006600;">openInfoWindow</span><span style="color: #66cc66;">&#40;</span>map.<span style="color: #006600;">getCenter</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> InfoWindowOptions<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>hasTail: <span style="color: #000000; font-weight: bold;">true</span>, tailHeight: <span style="color: #cc66cc;">5</span>, hasShadow: <span style="color: #000000; font-weight: bold;">true</span>, title:<span style="color: #0066CC;">name</span>, contentHTML:description<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://fightskillz.com/2009/09/flex-variables-anonymous-functions-and-for-loops/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Wordpress Automatic Upgrade</title>
		<link>http://fightskillz.com/2009/07/wordpress-automatic-upgrade/</link>
		<comments>http://fightskillz.com/2009/07/wordpress-automatic-upgrade/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 04:47:12 +0000</pubDate>
		<dc:creator>Yoav Givati</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://fightskillz.com/?p=1388</guid>
		<description><![CDATA[For a few versions now Wordpress has let you automatically upgrade it and your plugins. Every time an update would come around I'd try figure out how to activate it and fail. As a last resort you can specify ftp/ftps details and have it upgrade that way, but who wants to setup an ftp server [...]]]></description>
			<content:encoded><![CDATA[<p>For a few versions now Wordpress has let you automatically upgrade it and your plugins. Every time an update would come around I'd try figure out how to activate it and fail. As a last resort you can specify ftp/ftps details and have it upgrade that way, but who wants to setup an ftp server right?</p>
<p>Anyway, it turns out that aside from setting file permissions like everyone tells you to do to setup the automatic upgrade feature, the actual missing piece of the pie was to give ownership of the entire wordpress directory to the owner of the apache process.</p>
<p><strong>So, step 1: </strong>open up terminal and ssh to your server(use your ip address instead of all those 9s)</p>
<p># ssh root@99.99.999.999</p>
<p># [password]</p>
<p><strong>step 2:</strong> Now you're running a remote session to your server, open top</p>
<p># top</p>
<p><strong>step 3: </strong>Expand the window and look for processes name httpd or apache2, chances are they're owned by the user www-data. Say you have wordpress installed in /var/www/, enter in:</p>
<p># chown -R www-data /var/www</p>
<p>The above command changes the ownership of /var/www, which is a folder, recursively so it goes through and changes ownership of all the files and folders below it, and it's changing ownership to the user www-data.</p>
<p>Now log into wordpress and try auto upgrade.</p>
]]></content:encoded>
			<wfw:commentRss>http://fightskillz.com/2009/07/wordpress-automatic-upgrade/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Another Sidebar to Wordpress</title>
		<link>http://fightskillz.com/2009/01/adding-another-sidebar-to-wordpress/</link>
		<comments>http://fightskillz.com/2009/01/adding-another-sidebar-to-wordpress/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 21:34:45 +0000</pubDate>
		<dc:creator>Yoav Givati</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://fightskillz.com/?p=488</guid>
		<description><![CDATA[I'm using Wordpress 2.7 at the time of writing, but my theme is modified from the default theme from around version 2.5. My current sidebar uses the widgets feature with some manually added stuff, sort of a lazy way of customizing it. I keep adding to it and now I need a second one, which [...]]]></description>
			<content:encoded><![CDATA[<p>I'm using Wordpress 2.7 at the time of writing, but my theme is modified from the default theme from around version 2.5. My current sidebar uses the widgets feature with some manually added stuff, sort of a lazy way of customizing it. I keep adding to it and now I need a second one, which will inevitably require a wider site but my analytics shows most people these days have more than the formerly standard 1024x780 screen resolution and so it should be fine.</p>
<p>So if you're in the same boat as me, hand me that paddle, I'll show you what I did.</p>
<p><strong>In your theme folder open your functions.php file, and find the following code:</strong></p>
<pre class="php">&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <a href="http://www.php.net/function_exists"><span style="color: #000066;">function_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'register_sidebar'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>
register_sidebar<span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">'before_widget'</span> =&gt; <span style="color: #ff0000;">'
&lt;li id=&quot;%1$s&quot; class=&quot;widget %2$s&quot;&gt;'</span>,
<span style="color: #ff0000;">'after_widget'</span> =&gt; <span style="color: #ff0000;">'&lt;/li&gt;
&nbsp;
'</span>,
<span style="color: #ff0000;">'before_title'</span> =&gt; <span style="color: #ff0000;">'
&lt;h2 class=&quot;widgettitle&quot;&gt;'</span>,
<span style="color: #ff0000;">'after_title'</span> =&gt; <span style="color: #ff0000;">'&lt;/h2&gt;
&nbsp;
'</span>,
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p><strong>You may not have the above code, instead look for:</strong></p>
<pre class="php">&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <a href="http://www.php.net/function_exists"><span style="color: #000066;">function_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'register_sidebar'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>
register_sidebar<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p><strong>In either case we want to replace it with the following:</strong></p>
<pre class="php">&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <a href="http://www.php.net/function_exists"><span style="color: #000066;">function_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'register_sidebars'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>
register_sidebars<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p><em>Note: changed sidebar to sidebars,  and the number 2 indicates the total sidebars we want.</em></p>
<p><strong>In your theme folder open your index.php file, and find the following code:</strong></p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_sidebar<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p><strong>Or depending on your theme:</strong></p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">include</span><span style="color: #66cc66;">&#40;</span>TEMPLATEPATH.<span style="color: #ff0000;">&quot;/sidebar.php&quot;</span><span style="color: #66cc66;">&#41;</span>;?&gt;
&nbsp;</pre>
<p><strong>Since I want to add another right sidebar, add the following code below:</strong></p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_sidebar<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'2'</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p><em>Note: Anything between the ' ' is representative of the new file you have to create called in this case sidebar-2.php</em></p>
<p><strong>Or in the later case for consistency you can instead add:</strong></p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">include</span><span style="color: #66cc66;">&#40;</span>TEMPLATEPATH.<span style="color: #ff0000;">&quot;/sidebar-2.php&quot;</span><span style="color: #66cc66;">&#41;</span>;?&gt;
&nbsp;</pre>
<p><strong>The call for your sidebars in your index.php file should now look something like the following:</strong></p>
<pre class="php">&nbsp;
&lt;div id=<span style="color: #ff0000;">&quot;sidebar&quot;</span>&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_sidebar<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_sidebar<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'2'</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;
&nbsp;</pre>
<p><strong>In my case since I already had a sidebar, the "sidebar" div was inside sidebar.php. As you can see from the code above, it needs to be in the index.php file. Change the div id in sidebar.php to "sidebar1", and in sidebar-2.php to "sidebar2".</strong></p>
<p><em>Note: At this point you should see the two sidebars, and be able to add widgets or custom php. But it will likely appear below the other sidebar.</em></p>
<p><strong>Since I have css rules for sidebar, and not sidebar1 or 2, I can just re-assign some of the rules to sidebar 1, create a similar set for sidebar two and adjust the overall body and content width. This all depends on your theme and where you want your new sidebar.</strong></p>
<p><strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://fightskillz.com/2009/01/adding-another-sidebar-to-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flex 3-RegExp: Find Urls In Text And Html</title>
		<link>http://fightskillz.com/2008/12/flex-3-regexp-find-urls-in-text-and-html/</link>
		<comments>http://fightskillz.com/2008/12/flex-3-regexp-find-urls-in-text-and-html/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 19:42:53 +0000</pubDate>
		<dc:creator>Yoav Givati</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://fightskillz.com/?p=416</guid>
		<description><![CDATA[There are a number of situations where you'd want to grab the urls from a block of text. For example you may be loading in some external or dynamic data and want to make the links clickable, or change their colour. Regular expressions are used in a multitude of languages; they define patterns that can [...]]]></description>
			<content:encoded><![CDATA[<p>There are a number of situations where you'd want to grab the urls from a block of text. For example you may be loading in some external or dynamic data and want to make the links clickable, or change their colour. Regular expressions are used in a multitude of languages; they define patterns that can be matched against a string, thus certain key characters used in defining a RegExp have to be escaped so they are interpreted as special characters like <strong>\d</strong> matches any digit. In Actionscript, you can define a RegExp by either wrapping it in double quotes "", or forward slashes//. In each case you would have to escape any characters that match the wrapping in addition to the characters that need to be escaped in the actual pattern. Further more Actionscript requires you to separate out the last part of the regular expression, called flags, and insert it as the second argument when defining a new RegExp object.</p>
<p><strong>Here's how you find a url in text or html:</strong></p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> str:<span style="color: #0066CC;">String</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'This is a url www.fightskillz.com, and this is another one: &lt;a href=&quot;http://chalk-it-out.com&quot;&gt;Chalk It Out&lt;/a&gt;'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> reg:RegExp = <span style="color: #000000; font-weight: bold;">new</span> RegExp<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>b(((https?)://)|(www.))([a-z0-9-_.&amp;amp;=#/]+)&quot;</span>, <span style="color: #ff0000;">'i'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> result:<span style="color: #0066CC;">Object</span> = reg.<span style="color: #006600;">exec</span><span style="color: #66cc66;">&#40;</span>str<span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>result<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>
First off if you're new to Flex/Actionscript you have to copy and paste this into a function and the variables created will only be accessable within that function while it's running as they are created and destroyed as it runs. If you wanted more permanence you'd just define the variables outside the function. </p>
<p>
Now Let's break it down. The first <strong>\ </strong>is used as a character escape for Actionscript. In actionscript when defining a string within double quotes you'd escape a double that's part of the string like this<strong> "Look at this double quote \""</strong>.  <strong>\b </strong> searches for a word boundary ie: a whitespace, or the beginning or end of a string.The next part <strong>((https?)://)|(www.))</strong> defines the first part of a 'word' that passes for a url. It's made up of two substrings, the first looks for <strong>http</strong>, the question mark deems the preceding character optional, so it'll match to <strong>https</strong> as well. It then looks to see if the protocol is followed by <strong>://</strong>. The <strong>|</strong> character means <strong>OR</strong>, so if there is no protocol specified, it checks for <strong>(www.)</strong>. Next we have <strong>[a-z0-9-_.&amp;=#/]</strong> which is a list of characters a to z, 0 to 9, and various others commonly found in urls. This is followed by a <strong>+</strong> which instructs the pattern to match the preceding list of characters until it can't anymore. It can't anymore when it reaches whitespace, a single or double quote, brackets, or any other non-url character. Finally the RegExp flag <strong>i</strong> informs the pattern to be case insensitive.</p>
<p><strong>reg.exec(str);</strong> executes the pattern on the specified string and returns the results as an array. Since the example is only designed to match the first url it encounters and then stop, the array will only have one result. The method <strong>reg.exec(str)</strong> is interchangable with <strong>str.match(reg)</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://fightskillz.com/2008/12/flex-3-regexp-find-urls-in-text-and-html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert Milliseconds to Time (H:M:S)</title>
		<link>http://fightskillz.com/2008/12/convert-milliseconds-to-time-hms/</link>
		<comments>http://fightskillz.com/2008/12/convert-milliseconds-to-time-hms/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 20:28:52 +0000</pubDate>
		<dc:creator>Yoav Givati</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://chalk-it-out.com/blog/?p=29</guid>
		<description><![CDATA[Converting milliseconds to a time string can be a pain, especially when you're measuring something dynamic. In most languages I've come accross the Date object is calculated by the number of milliseconds that have passed since Jan 1, 1970. Because the different parts of a date are based on different bases ie: 60 minutes in [...]]]></description>
			<content:encoded><![CDATA[<p>Converting milliseconds to a time string can be a pain, especially when you're measuring something dynamic. In most languages I've come accross the Date object is calculated by the number of milliseconds that have passed since Jan 1, 1970. Because the different parts of a date are based on different bases ie: 60 minutes in an hour, 24 hours in a day etc. It's a lot easier to get the milliseconds passed since Jan1, 1970 and work with that value. This only works if you want to get the difference between two dates. If you were to subtract two dates(expressed as milliseconds) and get 432000000 milliseconds(5 days), then convert that to a Date object, the code would interpret 432000000 as Jan 6, 1970.</p>
<p>In another scenario I was just writing a podcast player in Flex 3/AIR and wanted to convert the Sound.length and SoundChannel.position values, both of which are measured in milliseconds, and display the length and current position of the episode in formats that would make sense. So I wrote a generic function that accepts milliseconds as an argument and returns the formatted time string.</p>
<pre class="actionscript">  <span style="color: #808080; font-style: italic;">/**    Milliseconds to Time String in Flex 3              **/</span>
  <span style="color: #808080; font-style: italic;">/**    Author: Yoav Givati [http://fightskillz.com]       **/</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fnMillisecondsToTimeCountUp<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">time</span>:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">//calculate playtime from milliseconds</span>
	<span style="color: #000000; font-weight: bold;">var</span> h:<span style="color: #0066CC;">Number</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">floor</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">time</span>/<span style="color: #cc66cc;">1000</span>/<span style="color: #cc66cc;">60</span>/<span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">//minutes left shows total minutes left plus hours, 1h5m = 65mins</span>
	<span style="color: #808080; font-style: italic;">//so we subtract the amount of 60's added by the hours to get just minutes</span>
	<span style="color: #000000; font-weight: bold;">var</span> m:<span style="color: #0066CC;">Number</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">floor</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">time</span>/<span style="color: #cc66cc;">1000</span>/<span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span>-<span style="color: #66cc66;">&#40;</span>h*<span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">//seconds left</span>
	<span style="color: #000000; font-weight: bold;">var</span> s:<span style="color: #0066CC;">Number</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">floor</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">time</span>/<span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span>-<span style="color: #66cc66;">&#40;</span>m*<span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//create string variables</span>
	<span style="color: #000000; font-weight: bold;">var</span> hours:<span style="color: #0066CC;">String</span>;
	<span style="color: #000000; font-weight: bold;">var</span> minutes:<span style="color: #0066CC;">String</span>;
	<span style="color: #000000; font-weight: bold;">var</span> seconds:<span style="color: #0066CC;">String</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">//make sure minutes and seconds are always two digits</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>m.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">length</span> == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		 minutes = <span style="color: #ff0000;">&quot;0&quot;</span>+m;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		 minutes = m.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>s.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">length</span> == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		seconds = <span style="color: #ff0000;">&quot;0&quot;</span>+s;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		seconds = s.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">//if hours or minutes are 0 we don't need to see them</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>h == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		hours = <span style="color: #ff0000;">''</span>;
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>m == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			minutes = <span style="color: #ff0000;">''</span>;
		<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
			minutes = minutes+<span style="color: #ff0000;">&quot;:&quot;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		hours = h+<span style="color: #ff0000;">&quot;:&quot;</span>
		minutes = minutes+<span style="color: #ff0000;">&quot;:&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">// after 1 hour passes the seconds become 4 digits long</span>
	<span style="color: #808080; font-style: italic;">// the last two of those digits represent the actual seconds</span>
	seconds = seconds.<span style="color: #0066CC;">slice</span><span style="color: #66cc66;">&#40;</span>seconds.<span style="color: #006600;">length</span><span style="color: #cc66cc;">-2</span>, seconds.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">return</span> hours+minutes+seconds;
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre>
<p>You'll notice that I'm using <code>Math.floor()</code>, it's crucial that you round down, because the way the hours are being calculated for example, rounding up would show one hour had passed after only a fraction of an hour, just rounding up the minutes or seconds would cause everything to be out of sync and the math would be concussed. For those of you who are confused I should clarify that <code>Math.floor(1.8)</code> would return a value of 1 and <code>Math.ceil(1.3)</code> would return a value of 2, the term 'round' is probably a misleading. If you were using this function to count down instead of up, you <strong>would</strong> use <code>Math.ceil()</code>(although still not for the hour value), you essentially want to stay on the 'other side' of the minute or second for as long as possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://fightskillz.com/2008/12/convert-milliseconds-to-time-hms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
