<?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>base42.nl &#187; code</title>
	<atom:link href="http://blog.base42.nl/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.base42.nl</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 19:40:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>AS3 spirograph with source code</title>
		<link>http://blog.base42.nl/2011/as3-spirograph-with-source-code/</link>
		<comments>http://blog.base42.nl/2011/as3-spirograph-with-source-code/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 19:18:54 +0000</pubDate>
		<dc:creator>jankees</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Spirograph]]></category>

		<guid isPermaLink="false">http://blog.base42.nl/?p=1489</guid>
		<description><![CDATA[I just worked a bit more on my AS3 spirograph tonight. This is the updated version with the full source code: Demo: Full source code: Please note that you need the Hype framework and Minimalcomps to compile this. package &#123; import hype.extended.util.ContextSavePNG; import hype.framework.display.BitmapCanvas; &#160; import com.bit101.components.CheckBox; import com.bit101.components.ColorChooser; import com.bit101.components.Label; import com.bit101.components.PushButton; import com.bit101.components.Slider; [...]]]></description>
			<content:encoded><![CDATA[<p>I just worked a bit more on my AS3 spirograph tonight. This is the updated version with the full source code:</p>
<h2>Demo:</h2>

        <div class="object_flashcontent" style="width: 650px; height: 450px;">
            <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="650px" height="450px">
                <param name="movie" value="http://test.base42.nl/spirograph/spirograph2.swf" />
                <param name="allowfullscreen" value="true" />
                <param name="allowscriptaccess" value="always" />
                <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="http://test.base42.nl/spirograph/spirograph2.swf" width="650px" height="450px">
                        <param name="allowfullscreen" value="true" />
                        <param name="allowscriptaccess" value="always" />
                <!--<![endif]-->
                <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
            </object>
        </div>
<h2>Full source code:</h2>
<p><span id="more-1489"></span></p>
<p>Please note that you need the <a href="http://www.hypeframework.org/">Hype framework</a> and <a href="http://minimalcomps.com">Minimalcomps</a> to compile this.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"> package <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> hype.<span style="color: #006600;">extended</span>.<span style="color: #006600;">util</span>.<span style="color: #006600;">ContextSavePNG</span>;
	<span style="color: #0066CC;">import</span> hype.<span style="color: #006600;">framework</span>.<span style="color: #006600;">display</span>.<span style="color: #006600;">BitmapCanvas</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">bit101</span>.<span style="color: #006600;">components</span>.<span style="color: #006600;">CheckBox</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">bit101</span>.<span style="color: #006600;">components</span>.<span style="color: #006600;">ColorChooser</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">bit101</span>.<span style="color: #006600;">components</span>.<span style="color: #006600;">Label</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">bit101</span>.<span style="color: #006600;">components</span>.<span style="color: #006600;">PushButton</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">bit101</span>.<span style="color: #006600;">components</span>.<span style="color: #006600;">Slider</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">StageAlign</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">StageScaleMode</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * @author Jankees van Woezik
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Spirograph <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> t : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _canvas : BitmapCanvas;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _original : Sprite;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _isVirgin : <span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">true</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _gearsVisual : Sprite;
		<span style="color: #808080; font-style: italic;">// minimalcomps.com</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _speedSlider : Slider;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _outerGearSlider : Slider;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _innerGearSlider : Slider;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _offsetPenSlider : Slider;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _penPointShape : Ball;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _drawAnimatedCheckbox : CheckBox;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _showWheelsCheckbox : CheckBox;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _colorPicker : ColorChooser;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Spirograph<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">scaleMode</span> = StageScaleMode.<span style="color: #006600;">NO_SCALE</span>;
			<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">align</span> = StageAlign.<span style="color: #006600;">TOP_LEFT</span>;
&nbsp;
			<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">RESIZE</span>, handleStageResize<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// gradient background (thanks to zwartekoffie.com)</span>
			addChild<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SiteBackground<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_original = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_canvas = <span style="color: #000000; font-weight: bold;">new</span> BitmapCanvas<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>, <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
			_canvas.<span style="color: #0066CC;">target</span> = _original;
			addChild<span style="color: #66cc66;">&#40;</span>_canvas<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_gearsVisual = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>_gearsVisual<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> controlY : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">10</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> randomize : PushButton = <span style="color: #000000; font-weight: bold;">new</span> PushButton<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #cc66cc;">10</span>, controlY, <span style="color: #ff0000;">&quot;Randomize settings&quot;</span>, randomSettings<span style="color: #66cc66;">&#41;</span>;
			randomize.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">172</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">new</span> Label<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #cc66cc;">10</span>, controlY += <span style="color: #cc66cc;">30</span>, <span style="color: #ff0000;">&quot;speed&quot;</span><span style="color: #66cc66;">&#41;</span>;
			_speedSlider = <span style="color: #000000; font-weight: bold;">new</span> Slider<span style="color: #66cc66;">&#40;</span>Slider.<span style="color: #006600;">HORIZONTAL</span>, <span style="color: #0066CC;">this</span>, <span style="color: #cc66cc;">80</span>, controlY + <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span>;
			_speedSlider.<span style="color: #006600;">minimum</span> = <span style="color: #cc66cc;">1</span>;
			_speedSlider.<span style="color: #006600;">value</span> = <span style="color: #cc66cc;">10</span>;
			_speedSlider.<span style="color: #006600;">maximum</span> = <span style="color: #cc66cc;">20</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">new</span> Label<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #cc66cc;">10</span>, controlY += <span style="color: #cc66cc;">15</span>, <span style="color: #ff0000;">&quot;outer gear (R)&quot;</span><span style="color: #66cc66;">&#41;</span>;
			_outerGearSlider = <span style="color: #000000; font-weight: bold;">new</span> Slider<span style="color: #66cc66;">&#40;</span>Slider.<span style="color: #006600;">HORIZONTAL</span>, <span style="color: #0066CC;">this</span>, <span style="color: #cc66cc;">80</span>, controlY + <span style="color: #cc66cc;">4</span>, change<span style="color: #66cc66;">&#41;</span>;
			_outerGearSlider.<span style="color: #006600;">minimum</span> = <span style="color: #cc66cc;">1</span>;
			_outerGearSlider.<span style="color: #006600;">value</span> = <span style="color: #cc66cc;">100</span>;
			_outerGearSlider.<span style="color: #006600;">maximum</span> = <span style="color: #cc66cc;">200</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">new</span> Label<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #cc66cc;">10</span>, controlY += <span style="color: #cc66cc;">15</span>, <span style="color: #ff0000;">&quot;inner gear (r)&quot;</span><span style="color: #66cc66;">&#41;</span>;
			_innerGearSlider = <span style="color: #000000; font-weight: bold;">new</span> Slider<span style="color: #66cc66;">&#40;</span>Slider.<span style="color: #006600;">HORIZONTAL</span>, <span style="color: #0066CC;">this</span>, <span style="color: #cc66cc;">80</span>, controlY + <span style="color: #cc66cc;">4</span>, change<span style="color: #66cc66;">&#41;</span>;
			_innerGearSlider.<span style="color: #006600;">minimum</span> = <span style="color: #cc66cc;">1</span>;
			_innerGearSlider.<span style="color: #006600;">value</span> = <span style="color: #cc66cc;">50</span>;
			_innerGearSlider.<span style="color: #006600;">maximum</span> = <span style="color: #cc66cc;">200</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">new</span> Label<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #cc66cc;">10</span>, controlY += <span style="color: #cc66cc;">15</span>, <span style="color: #ff0000;">&quot;offset pen (p)&quot;</span><span style="color: #66cc66;">&#41;</span>;
			_offsetPenSlider = <span style="color: #000000; font-weight: bold;">new</span> Slider<span style="color: #66cc66;">&#40;</span>Slider.<span style="color: #006600;">HORIZONTAL</span>, <span style="color: #0066CC;">this</span>, <span style="color: #cc66cc;">80</span>, controlY + <span style="color: #cc66cc;">4</span>, change<span style="color: #66cc66;">&#41;</span>;
			_offsetPenSlider.<span style="color: #006600;">minimum</span> = <span style="color: #cc66cc;">1</span>;
			_offsetPenSlider.<span style="color: #006600;">value</span> = <span style="color: #cc66cc;">6</span>;
			_offsetPenSlider.<span style="color: #006600;">maximum</span> = <span style="color: #cc66cc;">200</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">new</span> Label<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #cc66cc;">10</span>, controlY += <span style="color: #cc66cc;">19</span>, <span style="color: #ff0000;">&quot;line color&quot;</span><span style="color: #66cc66;">&#41;</span>;
			_colorPicker = <span style="color: #000000; font-weight: bold;">new</span> ColorChooser<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #cc66cc;">80</span>, controlY, 0x59c7b7<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_drawAnimatedCheckbox = <span style="color: #000000; font-weight: bold;">new</span> CheckBox<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #cc66cc;">12</span>, controlY += <span style="color: #cc66cc;">30</span>, <span style="color: #ff0000;">&quot;show animation&quot;</span>, toggleAnimated<span style="color: #66cc66;">&#41;</span>;
			_drawAnimatedCheckbox.<span style="color: #006600;">selected</span> = <span style="color: #000000; font-weight: bold;">true</span>;
&nbsp;
			_showWheelsCheckbox = <span style="color: #000000; font-weight: bold;">new</span> CheckBox<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #cc66cc;">12</span>, controlY += <span style="color: #cc66cc;">15</span>, <span style="color: #ff0000;">&quot;show gears&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> explanation : Label = <span style="color: #000000; font-weight: bold;">new</span> Label<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #cc66cc;">10</span>, controlY += <span style="color: #cc66cc;">20</span>, <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span>;
			explanation.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Formula<span style="color: #000099; font-weight: bold;">\n</span>x(t)=(R-r)*cos(t) + p*cos((R-r)*t/r) <span style="color: #000099; font-weight: bold;">\n</span>y(t)=(R-r)*sin(t) - p*sin((R-r)*t/r)&quot;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">new</span> ContextSavePNG<span style="color: #66cc66;">&#40;</span>_canvas, <span style="color: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_penPointShape = <span style="color: #000000; font-weight: bold;">new</span> Ball<span style="color: #66cc66;">&#40;</span>_colorPicker.<span style="color: #006600;">value</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>_penPointShape<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, handleEnterFrame<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			randomSettings<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleEnterFrame<span style="color: #66cc66;">&#40;</span>event : Event<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_drawAnimatedCheckbox.<span style="color: #006600;">selected</span><span style="color: #66cc66;">&#41;</span> renderTick<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleStageResize<span style="color: #66cc66;">&#40;</span>event : Event<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			removeChild<span style="color: #66cc66;">&#40;</span>_canvas<span style="color: #66cc66;">&#41;</span>;
			_canvas.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_canvas = <span style="color: #000000; font-weight: bold;">null</span>;
			_canvas = <span style="color: #000000; font-weight: bold;">new</span> BitmapCanvas<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>, <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span>, <span style="color: #000000; font-weight: bold;">true</span>, 0xffffff<span style="color: #66cc66;">&#41;</span>;
			_canvas.<span style="color: #0066CC;">target</span> = _original;
			addChildAt<span style="color: #66cc66;">&#40;</span>_canvas, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
			clearCanvas<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> toggleAnimated<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span> : Event<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			clearCanvas<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>_drawAnimatedCheckbox.<span style="color: #006600;">selected</span><span style="color: #66cc66;">&#41;</span> drawStatic<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> change<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span> : Event<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			clearCanvas<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_drawAnimatedCheckbox<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>_drawAnimatedCheckbox.<span style="color: #006600;">selected</span><span style="color: #66cc66;">&#41;</span> drawStatic<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> drawStatic<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: #000000; font-weight: bold;">var</span> leni : uint = <span style="color: #cc66cc;">6000</span>;
			<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i : uint = <span style="color: #cc66cc;">0</span>; i <span style="color: #66cc66;">&lt;</span> leni; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				renderTick<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> clearCanvas<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			_canvas.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_isVirgin = <span style="color: #000000; font-weight: bold;">true</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> randomSettings<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span> : Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			_outerGearSlider.<span style="color: #006600;">value</span> = <span style="color: #0066CC;">Random</span>.<span style="color: #006600;">between</span><span style="color: #66cc66;">&#40;</span>_outerGearSlider.<span style="color: #006600;">maximum</span> - <span style="color: #cc66cc;">50</span>, _outerGearSlider.<span style="color: #006600;">maximum</span><span style="color: #66cc66;">&#41;</span>;
			_innerGearSlider.<span style="color: #006600;">value</span> = <span style="color: #0066CC;">Random</span>.<span style="color: #006600;">between</span><span style="color: #66cc66;">&#40;</span>_innerGearSlider.<span style="color: #006600;">minimum</span>, _outerGearSlider.<span style="color: #006600;">value</span><span style="color: #66cc66;">&#41;</span>;
			_offsetPenSlider.<span style="color: #006600;">value</span> = <span style="color: #0066CC;">Random</span>.<span style="color: #006600;">between</span><span style="color: #66cc66;">&#40;</span>_offsetPenSlider.<span style="color: #006600;">minimum</span>, _innerGearSlider.<span style="color: #006600;">value</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> renderTick<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			t += <span style="color: #66cc66;">&#40;</span>_speedSlider.<span style="color: #006600;">value</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_offsetPenSlider.<span style="color: #006600;">value</span> <span style="color: #66cc66;">&gt;</span> _innerGearSlider.<span style="color: #006600;">value</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				_offsetPenSlider.<span style="color: #006600;">value</span> = _innerGearSlider.<span style="color: #006600;">value</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_innerGearSlider.<span style="color: #006600;">value</span> <span style="color: #66cc66;">&gt;</span> _outerGearSlider.<span style="color: #006600;">value</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				_innerGearSlider.<span style="color: #006600;">value</span> = _outerGearSlider.<span style="color: #006600;">value</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			_original.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>, _colorPicker.<span style="color: #006600;">value</span>, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
			_original.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span>_penPointShape.<span style="color: #006600;">x</span>, _penPointShape.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> a : <span style="color: #0066CC;">Number</span> = _outerGearSlider.<span style="color: #006600;">value</span>;
			<span style="color: #000000; font-weight: bold;">var</span> b : <span style="color: #0066CC;">Number</span> = _innerGearSlider.<span style="color: #006600;">value</span>;
			<span style="color: #000000; font-weight: bold;">var</span> o : <span style="color: #0066CC;">Number</span> = _offsetPenSlider.<span style="color: #006600;">value</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> newx : <span style="color: #0066CC;">Number</span>;
			<span style="color: #000000; font-weight: bold;">var</span> newy : <span style="color: #0066CC;">Number</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// http://en.wikipedia.org/wiki/Spirograph</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">// as found on http://linuxgazette.net/133/luana.html</span>
			<span style="color: #808080; font-style: italic;">//</span>
			<span style="color: #808080; font-style: italic;">// x(t)=(R-r)*cos(t) + p*cos((R-r)*t/r)</span>
			<span style="color: #808080; font-style: italic;">// y(t)=(R-r)*sin(t) - p*sin((R-r)*t/r)</span>
			<span style="color: #808080; font-style: italic;">//</span>
			<span style="color: #808080; font-style: italic;">// R, the radius of the fixed circle;</span>
			<span style="color: #808080; font-style: italic;">// r, the radius of the moving circle;</span>
			<span style="color: #808080; font-style: italic;">// p, the distance from the pen to the moving circle center.</span>
			<span style="color: #808080; font-style: italic;">// O, The center of the fixed circle</span>
&nbsp;
			newx = <span style="color: #66cc66;">&#40;</span>a - b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span> + o <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>a - b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> t <span style="color: #66cc66;">/</span> b<span style="color: #66cc66;">&#41;</span>;
			newy = <span style="color: #66cc66;">&#40;</span>a - b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span> + o <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>a - b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> t <span style="color: #66cc66;">/</span> b<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_penPointShape.<span style="color: #006600;">x</span> = newx + <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;
			_penPointShape.<span style="color: #006600;">y</span> = newy + <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;
&nbsp;
			_penPointShape.<span style="color: #0066CC;">color</span> = _colorPicker.<span style="color: #006600;">value</span>;
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>_isVirgin<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				_original.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>_penPointShape.<span style="color: #006600;">x</span>, _penPointShape.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			_gearsVisual.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">clear</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>_showWheelsCheckbox.<span style="color: #006600;">selected</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> centerInnerCircleX : <span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span>a - b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #000000; font-weight: bold;">var</span> centerInnerCircleY : <span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span>a - b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
				_gearsVisual.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xfffe8e, <span style="color: #cc66cc;">0.3</span><span style="color: #66cc66;">&#41;</span>;
				_gearsVisual.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawCircle</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>, <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>, a<span style="color: #66cc66;">&#41;</span>;
				_gearsVisual.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xfe6cc7, <span style="color: #cc66cc;">0.3</span><span style="color: #66cc66;">&#41;</span>;
				_gearsVisual.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawCircle</span><span style="color: #66cc66;">&#40;</span>centerInnerCircleX, centerInnerCircleY, b<span style="color: #66cc66;">&#41;</span>;
				_gearsVisual.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xfe6cc7, <span style="color: #cc66cc;">0.3</span><span style="color: #66cc66;">&#41;</span>;
				_gearsVisual.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawCircle</span><span style="color: #66cc66;">&#40;</span>centerInnerCircleX, centerInnerCircleY, <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>;
				_gearsVisual.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			_canvas.<span style="color: #006600;">capture</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_original.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_isVirgin = <span style="color: #000000; font-weight: bold;">false</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0066CC;">import</span> nl.<span style="color: #006600;">inlet42</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">view</span>.<span style="color: #006600;">StageProvider</span>;
&nbsp;
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">epologee</span>.<span style="color: #006600;">util</span>.<span style="color: #006600;">ColorUtils</span>;
&nbsp;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">GradientType</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Matrix</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Ball <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _color : uint;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Ball<span style="color: #66cc66;">&#40;</span>inColor : uint<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">color</span> = inColor;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">color</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">color</span> : uint<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_color == <span style="color: #0066CC;">color</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span>;
		_color = <span style="color: #0066CC;">color</span>;
		<span style="color: #0066CC;">with</span><span style="color: #66cc66;">&#40;</span>graphics<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>_color, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
			drawCircle<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">class</span> SiteBackground <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SiteBackground<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			initUI<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
			addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ADDED_TO_STAGE</span>, initUI, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> initUI<span style="color: #66cc66;">&#40;</span>event : Event<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		removeEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ADDED_TO_STAGE</span>, initUI<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">RESIZE</span>, handleResize<span style="color: #66cc66;">&#41;</span>;
		handleResize<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleResize<span style="color: #66cc66;">&#40;</span>event : Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		graphics.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #000000; font-weight: bold;">var</span> colors : <span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span>0xfdfdfb, 0xeae7e0<span style="color: #66cc66;">&#93;</span>;
		<span style="color: #000000; font-weight: bold;">var</span> alphas : <span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>;
		<span style="color: #000000; font-weight: bold;">var</span> ratios : <span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#93;</span>;
		<span style="color: #000000; font-weight: bold;">var</span> matrix : Matrix = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		matrix.<span style="color: #006600;">createGradientBox</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>, <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>, <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span> - <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>, <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span> - <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;
		graphics.<span style="color: #0066CC;">beginGradientFill</span><span style="color: #66cc66;">&#40;</span>GradientType.<span style="color: #006600;">RADIAL</span>, colors, alphas, ratios, matrix<span style="color: #66cc66;">&#41;</span>;
		graphics.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>, <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #0066CC;">Random</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> between<span style="color: #66cc66;">&#40;</span>inFrom : <span style="color: #0066CC;">Number</span>, inTo : <span style="color: #0066CC;">Number</span>, inFloat : <span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> from : <span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span>inFrom <span style="color: #66cc66;">&lt;</span> inTo<span style="color: #66cc66;">&#41;</span> ? inFrom : inTo;
		<span style="color: #000000; font-weight: bold;">var</span> to : <span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span>inTo <span style="color: #66cc66;">&gt;</span> inFrom<span style="color: #66cc66;">&#41;</span> ? inTo : inFrom;
		<span style="color: #b1b100;">return</span> inFloat ? <span style="color: #66cc66;">&#40;</span>from + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>to - from<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #66cc66;">&#40;</span>from + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>to - from<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.base42.nl/2011/as3-spirograph-with-source-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>LogMeister open source</title>
		<link>http://blog.base42.nl/2010/logmeister-open-source-on-github/</link>
		<comments>http://blog.base42.nl/2010/logmeister-open-source-on-github/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 09:27:25 +0000</pubDate>
		<dc:creator>jankees</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.base42.nl/?p=1167</guid>
		<description><![CDATA[There are several loggers used by Flash developers, some like logger A and others like B. I switch between loggers from time to time. I like Trazzle because it&#8217;s lightning fast and I use MonsterDebugger because is really extensive. I needed an easy way to switch between loggers. That&#8217;s why I created LogMeister. LogMeister is [...]]]></description>
			<content:encoded><![CDATA[<p>There are several loggers used by Flash developers, some like logger A and others like B. I switch between loggers from time to time. I like Trazzle because it&#8217;s lightning fast and I use MonsterDebugger because is really extensive. I needed an easy way to switch between loggers. That&#8217;s why I created LogMeister. LogMeister is a wrapper which you can use for every logger and I added the ones that that I have used over the last few years.</p>
<p>It&#8217;s really easy to use. The first thing you need to do is add the logger you need (do this once in you document class).</p>
<p><span id="more-1167"></span></p>
<p>This is an example how to add all available loggers (not recommended):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> logmeister.<span style="color: #006600;">LogMeister</span>;
<span style="color: #0066CC;">import</span> logmeister.<span style="color: #006600;">connectors</span>.<span style="color: #66cc66;">*</span>;
&nbsp;
LogMeister.<span style="color: #006600;">addLogger</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TrazzleConnector<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>, <span style="color: #ff0000;">&quot;Application Name&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
LogMeister.<span style="color: #006600;">addLogger</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SosMaxConnector<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
LogMeister.<span style="color: #006600;">addLogger</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> MonsterDebuggerConnector<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
LogMeister.<span style="color: #006600;">addLogger</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> YalogConnector<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
LogMeister.<span style="color: #006600;">addLogger</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> FlashConnector<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>After you have done that, it&#8217;s super easy to use (and no imports!!). In LogMeister there are different levels for sending messages, it&#8217;s recommended that you use these levels. In most loggers these levels have different colors.</p>
<p><img class="alignnone size-large wp-image-1169" title="trazzleonepointfive" src="http://blog.base42.nl/wp-content/uploads/trazzleonepointfive-650x238.png" alt="" width="650" height="238" /></p>
<p>Example usage:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">critical<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'critical'</span><span style="color: #66cc66;">&#41;</span>;
debug<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'debug'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">error</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'error'</span><span style="color: #66cc66;">&#41;</span>;
fatal<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'fatal'</span><span style="color: #66cc66;">&#41;</span>;
info<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'info'</span><span style="color: #66cc66;">&#41;</span>;
notice<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'notice'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">status</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'status'</span><span style="color: #66cc66;">&#41;</span>;
warn<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'warn'</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>A zipfile can be downloaded at <a href="http://github.com/base42/LogMeister/downloads">github.com</a>. The zip file contains the source and working examples (CS4 &amp; code only).</p>
<p>If you have any suggestions please let me know (or <abbr title="In software engineering, a project fork happens when developers take a copy of source code from one software package and start independent">fork</abbr> me at GitHub).</p>
<p>Happy logging.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.base42.nl/2010/logmeister-open-source-on-github/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Logger</title>
		<link>http://blog.base42.nl/2009/logger/</link>
		<comments>http://blog.base42.nl/2009/logger/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 20:33:09 +0000</pubDate>
		<dc:creator>jankees</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.base42.nl/?p=942</guid>
		<description><![CDATA[When building your first website in Flash you initially use the trace() function. But after a while you start to feel the need for more. There are a lot of &#8216;loggers&#8217; available on the web. Personally I prefer Trazzle because it&#8217;s a very lightweight native mac application. But when working with colleagues who don&#8217;t use [...]]]></description>
			<content:encoded><![CDATA[<p>When building your first website in Flash you initially use the trace() function. But after a while you start to feel the need for more. There are a lot of &#8216;loggers&#8217; available on the web. Personally I prefer <a href="http://www.nesium.com/products/trazzle/" target="_blank">Trazzle</a> because it&#8217;s a very lightweight native mac application. But when working with colleagues who don&#8217;t use a mac, Trazzle is no option. It can be hard to choose a good logger everybody likes. That is why I created a project that enables you to use all the loggers you want with one simple script. I called it &#8216;Logger&#8217; (don&#8217;t laugh). And you can use it with the following syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">Logger.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Logger traces a debug message&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>That is not bad, right? Almost every logger has different debug levels, that is why I implemented the most important ones in the script (<em>debug/error/fatal/info/critical/status/warning and notice</em>). To log a message choose one of the following;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">Logger.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Logger traces a debug message&quot;</span><span style="color: #66cc66;">&#41;</span>;
Logger.<span style="color: #0066CC;">error</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Logger traces an error message&quot;</span><span style="color: #66cc66;">&#41;</span>;
Logger.<span style="color: #006600;">fatal</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Logger traces a fatal message&quot;</span><span style="color: #66cc66;">&#41;</span>;
Logger.<span style="color: #006600;">info</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Logger traces an info message&quot;</span><span style="color: #66cc66;">&#41;</span>;
Logger.<span style="color: #006600;">critical</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Logger traces a critical message&quot;</span><span style="color: #66cc66;">&#41;</span>;
Logger.<span style="color: #0066CC;">status</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Logger traces a status message&quot;</span><span style="color: #66cc66;">&#41;</span>;
Logger.<span style="color: #006600;">warning</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Logger traces a warning  message&quot;</span><span style="color: #66cc66;">&#41;</span>;
Logger.<span style="color: #006600;">notice</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;And finally Logger traces a notice message&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Before you do this you first need to initialize the loggers you want. I created connectors for <a href="http://www.nesium.com/products/trazzle/" target="_blank">Trazzle</a>, <a href="http://fdt.powerflasher.de/index.php?id=6" target="_blank">SOSMax</a>, <a href="http://demonsterdebugger.com/" target="_blank">DeMonsterDebugger</a>, <a href="http://yala.acidcats.nl/" target="_blank">Yala</a> and Flash (trace). To enable all these loggers together (which is not recommended) call;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">Logger.<span style="color: #006600;">addLoggers</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #000000; font-weight: bold;">new</span> MonsterDebuggerConnector<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #000000; font-weight: bold;">new</span> FlashConnector<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #000000; font-weight: bold;">new</span> TrazzleConnector<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #000000; font-weight: bold;">new</span> YalogConnector<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #000000; font-weight: bold;">new</span> SosMaxConnector<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This is how the output looks on all the different connectors (note how every logger shows the line number and class of the log);</p>
<p><strong>Trazzle </strong>(<a href="http://www.nesium.com/products/trazzle/" target="_blank">website</a>)</p>
<p><img class="alignnone size-large wp-image-945" title="Screen shot 2009-09-10 at 17.44.27" src="http://blog.base42.nl/wp-content/uploads/Screen-shot-2009-09-10-at-17.44.27-650x200.png" alt="Screen shot 2009-09-10 at 17.44.27" width="650" height="200" /></p>
<p><strong>De Monster Debugger</strong> (<a href="http://demonsterdebugger.com/" target="_blank">website</a>)</p>
<p><img class="alignnone size-large wp-image-946" title="Screen shot 2009-09-10 at 17.44.58" src="http://blog.base42.nl/wp-content/uploads/Screen-shot-2009-09-10-at-17.44.58-650x525.png" alt="Screen shot 2009-09-10 at 17.44.58" width="650" height="525" /></p>
<p><strong>SOSMax</strong> (<a href="http://fdt.powerflasher.de/index.php?id=6" target="_blank">website</a>)</p>
<p><img title="Screen shot 2009-09-10 at 17.46.17" src="http://blog.base42.nl/wp-content/uploads/Screen-shot-2009-09-10-at-17.46.17-650x236.png" alt="Screen shot 2009-09-10 at 17.46.17" width="650" height="236" /></p>
<p><strong>Yala</strong> (<a href="http://yala.acidcats.nl/" target="_blank">online version</a>)</p>
<p><strong><img class="alignnone size-large wp-image-950" title="Screen shot 2009-09-10 at 22.07.51" src="http://blog.base42.nl/wp-content/uploads/Screen-shot-2009-09-10-at-22.07.51-650x460.png" alt="Screen shot 2009-09-10 at 22.07.51" width="650" height="460" /></strong></p>
<p><strong>Flash:</strong></p>
<p><img title="Screen shot 2009-09-10 at 17.43.57" src="http://blog.base42.nl/wp-content/uploads/Screen-shot-2009-09-10-at-17.43.57-650x160.png" alt="Screen shot 2009-09-10 at 17.43.57" width="650" height="160" /></p>
<p>I created a <a href="http://blog.base42.nl/wp-content/uploads/Logger20090910r1.zip">zip package</a> with everything you need (Demo FLA and source). If you have any suggestions please let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.base42.nl/2009/logger/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Land of the logging</title>
		<link>http://blog.base42.nl/2009/land-of-the-logging/</link>
		<comments>http://blog.base42.nl/2009/land-of-the-logging/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 14:48:04 +0000</pubDate>
		<dc:creator>jankees</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.base42.nl/?p=930</guid>
		<description><![CDATA[Today I have built a wrapper around some loggers for Flash (Trazzle, Yalog, Monster Debugger and SOS Max). I am currently cleaning the code, but I will post the code as soon as possible. This is a screenshot of my current setup&#8230;.]]></description>
			<content:encoded><![CDATA[<p>Today I have built a wrapper around some loggers for Flash (<a href="http://www.nesium.com/products/trazzle/" target="_blank">Trazzle</a>, <a href="http://yala.acidcats.nl/" target="_blank">Yalog</a>, <a href="http://demonsterdebugger.com/" target="_blank">Monster Debugger</a> and <a href="http://fdt.powerflasher.de/index.php?id=6" target="_blank">SOS Max</a>).</p>
<p>I am currently cleaning the code, but I will post the code as soon as possible.</p>
<p>This is a screenshot of my current setup&#8230;.</p>
<p><a href="http://blog.base42.nl/wp-content/uploads/Screen-shot-2009-09-09-at-16.19.36.png"><img class="alignnone size-large wp-image-931" title="Screen shot 2009-09-09 at 16.19.36" src="http://blog.base42.nl/wp-content/uploads/Screen-shot-2009-09-09-at-16.19.36-650x379.png" alt="Screen shot 2009-09-09 at 16.19.36" width="650" height="379" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.base42.nl/2009/land-of-the-logging/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Automatic font size adjuster</title>
		<link>http://blog.base42.nl/2009/automatic-font-size-adjuster/</link>
		<comments>http://blog.base42.nl/2009/automatic-font-size-adjuster/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 10:42:16 +0000</pubDate>
		<dc:creator>jankees</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.base42.nl/?p=895</guid>
		<description><![CDATA[First I have to say sorry to all the not &#8216;actionscript-geeks&#8217;, but I have another script I want to share. I made a TextField behaviour that might come in handy for other people too.. I made a short video to show how it works. It is called AutomaticFontSizeBehaviour AutomaticFonSizeBehavior :) package &#123; import flash.events.Event; import [...]]]></description>
			<content:encoded><![CDATA[<p>First I have to say sorry to all the not &#8216;actionscript-geeks&#8217;, but I have another script I want to share.  I made a TextField behaviour that might come in handy for other people too.. I made a short video to show how it works.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/MMGFrLBFvUo&amp;hl=en&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/MMGFrLBFvUo&amp;hl=en&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>It is called <del datetime="2009-10-08T06:57:20+00:00">AutomaticFontSizeBehaviour</del> AutomaticFonSizeBehavior :)</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package  
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">KeyboardEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextField</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextFormat</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 *  @author Jankees.van.Woezik
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AutomaticFonSizeBehavior 
	<span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _textField:<span style="color: #0066CC;">TextField</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _startSize:<span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _currentSize:<span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _prevText:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _maxHeight:<span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _minimalFontSize:uint;
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Usage:
		 * 
		 * _updater = new AutomaticFonSizeBehavior(textField);
		 * 
		 * // this is enough for input fields, if you set text using code you should call the update function after you have set the text like this:
		 * 
		 * _updater.update();
		 * 
		 */</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AutomaticFonSizeBehavior<span style="color: #66cc66;">&#40;</span>inTextField:<span style="color: #0066CC;">TextField</span>,inStartSize:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">40</span>,inMinimalFontSize:uint = <span style="color: #cc66cc;">9</span>, willUpdateOnInput = <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span> 
		<span style="color: #66cc66;">&#123;</span>
			_minimalFontSize = inMinimalFontSize;
			_startSize = inStartSize;
			_currentSize = inStartSize;
			_textField = inTextField;
			_prevText = <span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
			_maxHeight = _textField.<span style="color: #0066CC;">height</span>;
&nbsp;
			_textField.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">REMOVED_FROM_STAGE</span>,dispose<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>willUpdateOnInput<span style="color: #66cc66;">&#41;</span> addEventListeners<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			setFontSize<span style="color: #66cc66;">&#40;</span>_startSize<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			update<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #66cc66;">&#40;</span>event:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> 
		<span style="color: #66cc66;">&#123;</span>
			_textField.<span style="color: #006600;">scrollV</span> = <span style="color: #cc66cc;">0</span>;
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_prevText.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&gt;</span> _textField.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span>
                setFontSize<span style="color: #66cc66;">&#40;</span>_startSize<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>_maxHeight <span style="color: #66cc66;">&lt;</span> _textField.<span style="color: #0066CC;">textHeight</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span> <span style="color: #66cc66;">*</span> _textField.<span style="color: #006600;">numLines</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> 
			<span style="color: #66cc66;">&#123;</span> 
				<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_currentSize <span style="color: #66cc66;">&lt;</span>= _minimalFontSize<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">break</span>;
				setFontSize<span style="color: #66cc66;">&#40;</span>_currentSize - <span style="color: #cc66cc;">0.5</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>_currentSize <span style="color: #66cc66;">&lt;</span>= _minimalFontSize<span style="color: #66cc66;">&#41;</span> 
			<span style="color: #66cc66;">&#123;</span>
				_textField.<span style="color: #0066CC;">text</span> = _prevText;
			<span style="color: #66cc66;">&#125;</span> 
			<span style="color: #b1b100;">else</span> 
			<span style="color: #66cc66;">&#123;</span>
				_prevText = _textField.<span style="color: #0066CC;">text</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> addEventListeners<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> 
		<span style="color: #66cc66;">&#123;</span>
			_textField.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">CHANGE</span>,update<span style="color: #66cc66;">&#41;</span>;
			_textField.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_UP</span>,update<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> setFontSize<span style="color: #66cc66;">&#40;</span>inSize:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> 
		<span style="color: #66cc66;">&#123;</span>
			_currentSize = inSize;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> currentTextFormat:<span style="color: #0066CC;">TextFormat</span> = _textField.<span style="color: #0066CC;">getTextFormat</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			currentTextFormat.<span style="color: #0066CC;">size</span> = _currentSize;
&nbsp;
			_textField.<span style="color: #0066CC;">setTextFormat</span><span style="color: #66cc66;">&#40;</span>currentTextFormat<span style="color: #66cc66;">&#41;</span>;
			_textField.<span style="color: #006600;">defaultTextFormat</span> = currentTextFormat;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Dispose everything
		 */</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> dispose<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> 
		<span style="color: #66cc66;">&#123;</span>
			_textField.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_UP</span>,update<span style="color: #66cc66;">&#41;</span>;
			_textField.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">CHANGE</span>,update<span style="color: #66cc66;">&#41;</span>;
			_textField.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">REMOVED_FROM_STAGE</span>,dispose<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_textField = <span style="color: #000000; font-weight: bold;">null</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>update:</strong> Thanks to Thijs for the update! Copy &amp; paste is now supported!<br />
<strong>update:</strong> Thanks to Sandro Padin for the improvements!!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.base42.nl/2009/automatic-font-size-adjuster/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>AS3 SRT Subtitle parser</title>
		<link>http://blog.base42.nl/2009/as3-srt-subtitle-parser/</link>
		<comments>http://blog.base42.nl/2009/as3-srt-subtitle-parser/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 18:49:32 +0000</pubDate>
		<dc:creator>jankees</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.base42.nl/?p=862</guid>
		<description><![CDATA[Update (23 november 2011): I uploaded a working videoplayer with subtitles to GitHub if you would like: https://github.com/base42/Videomeister Today I started to work on a .srt driven subtitle system for Flash, I just finished that converts the srt file to a native flash object. Below is a short sample of a srt file. 1 00:00:20,000 [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><strong>Update (23 november 2011):</strong><br />
I uploaded a working videoplayer with subtitles to GitHub if you would like: <a href="https://github.com/base42/Videomeister">https://github.com/base42/Videomeister</a></p></blockquote>
<p>Today I started to work on a <a href="http://en.wikipedia.org/wiki/SubRip#SubRip_Format">.srt</a> driven subtitle system for Flash, I just finished that converts the srt file to a native flash object.</p>
<p>Below is a short sample of a srt file.</p>

<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">1
00:00:20,000 --&amp;gt; 00:00:24,400
In connection with a dramatic increase
in crime in certain neighbourhoods,
&nbsp;
2
00:00:24,600 --&amp;gt; 00:00:27,800
the government is implementing a new policy...</pre></div></div>

<p>I created the following classes to read these files. (any suggestions are welcome!)</p>
<p><em>Special thanks to <a href="http://www.tyz.nl">Thijs Broerse</a> of <a href="http://www.mediamonks.com/">Media Monks</a>, for the stringToSeconds function</em></p>
<p><strong>SubtitleParser.as</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package nl.<span style="color: #006600;">inlet42</span>.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">subtitles</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 *	@author Jankees.van.Woezik
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SubtitleParser <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> parseSRT<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span> : <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">Array</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> result : <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>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> lines : <span style="color: #0066CC;">Array</span>;
			<span style="color: #000000; font-weight: bold;">var</span> translation : SubTitleData;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> blocks : <span style="color: #0066CC;">Array</span> = <span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">/</span>^<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span>-<span style="color: #cc66cc;">9</span><span style="color: #66cc66;">&#93;</span>+$<span style="color: #66cc66;">/</span>gm<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> block : <span style="color: #0066CC;">String</span> <span style="color: #b1b100;">in</span> blocks<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				translation = <span style="color: #000000; font-weight: bold;">new</span> SubTitleData<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				lines = block.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> line : <span style="color: #0066CC;">String</span> <span style="color: #b1b100;">in</span> lines<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					<span style="color: #808080; font-style: italic;">//all lines in a translation block</span>
					<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>trim<span style="color: #66cc66;">&#40;</span>line<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
						<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>line.<span style="color: #006600;">match</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;--&amp;gt;&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
							<span style="color: #808080; font-style: italic;">//timecodes line</span>
							<span style="color: #000000; font-weight: bold;">var</span> timecodes : <span style="color: #0066CC;">Array</span> = line.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">/</span><span style="color: #66cc66;">&#91;</span> <span style="color: #66cc66;">&#93;</span>+--<span style="color: #66cc66;">&amp;</span>gt;<span style="color: #66cc66;">&#91;</span> <span style="color: #66cc66;">&#93;</span>+<span style="color: #66cc66;">/</span>gm<span style="color: #66cc66;">&#41;</span>;
							<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>timecodes.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">!</span>= <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
								<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Translation error, something wrong with the start or end time&quot;</span><span style="color: #66cc66;">&#41;</span>;
							<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
								translation.<span style="color: #0066CC;">start</span> = stringToSeconds<span style="color: #66cc66;">&#40;</span>timecodes<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
								translation.<span style="color: #0066CC;">end</span> = stringToSeconds<span style="color: #66cc66;">&#40;</span>timecodes<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
								translation.<span style="color: #0066CC;">duration</span> = translation.<span style="color: #0066CC;">end</span> - translation.<span style="color: #0066CC;">start</span>;
&nbsp;
								<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>translation.<span style="color: #0066CC;">duration</span> <span style="color: #66cc66;">&amp;</span>lt; <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
									<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Translation error, something wrong with the start or end time&quot;</span><span style="color: #66cc66;">&#41;</span>;
								<span style="color: #66cc66;">&#125;</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>
							<span style="color: #808080; font-style: italic;">//translation line</span>
							<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>translation.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">!</span>= <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> line = <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> + trim<span style="color: #66cc66;">&#40;</span>line<span style="color: #66cc66;">&#41;</span>;
							translation.<span style="color: #0066CC;">text</span> += line;
						<span style="color: #66cc66;">&#125;</span>
					<span style="color: #66cc66;">&#125;</span>
				<span style="color: #66cc66;">&#125;</span>
				result.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>translation<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">return</span> result;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> trim<span style="color: #66cc66;">&#40;</span>p_string : <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>p_string == <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;">return</span> <span style="color: #ff0000;">''</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">return</span> p_string.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">/</span>^\s+<span style="color: #66cc66;">|</span>\s+$<span style="color: #66cc66;">/</span>g, <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Convert a string to seconds, with these formats supported:
		 * 00:03:00.1 / 03:00.1 / 180.1s / 3.2m / 3.2h / 00:01:53,800
		 *
		 * Special thanks to Thijs Broerse of Media Monks!
		 *
		 **/</span>
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> stringToSeconds<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">string</span> : <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> arr : <span style="color: #0066CC;">Array</span> = <span style="color: #0066CC;">string</span>.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">':'</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> sec : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">string</span>.<span style="color: #0066CC;">substr</span><span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">'s'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				sec = <span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">string</span>.<span style="color: #0066CC;">substr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #0066CC;">string</span>.<span style="color: #0066CC;">length</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">string</span>.<span style="color: #0066CC;">substr</span><span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">'m'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				sec = <span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">string</span>.<span style="color: #0066CC;">substr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #0066CC;">string</span>.<span style="color: #0066CC;">length</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">60</span>;
			<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">string</span>.<span style="color: #0066CC;">substr</span><span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">'h'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				sec = <span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">string</span>.<span style="color: #0066CC;">substr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #0066CC;">string</span>.<span style="color: #0066CC;">length</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">3600</span>;
			<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>arr.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&amp;</span>gt; <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>arr<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&amp;</span>amp;<span style="color: #66cc66;">&amp;</span>amp; <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span>arr<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">','</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">!</span>= -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> arr<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span>arr<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">/</span>\,<span style="color: #66cc66;">/</span>, <span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
				sec = <span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#40;</span>arr<span style="color: #66cc66;">&#91;</span>arr.<span style="color: #0066CC;">length</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
				sec += <span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#40;</span>arr<span style="color: #66cc66;">&#91;</span>arr.<span style="color: #0066CC;">length</span> - <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">60</span>;
				<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>arr.<span style="color: #0066CC;">length</span> == <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					sec += <span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#40;</span>arr<span style="color: #66cc66;">&#91;</span>arr.<span style="color: #0066CC;">length</span> - <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">3600</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>
				sec = <span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">string</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">return</span> sec;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>SubTitleData.as</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package nl.<span style="color: #006600;">inlet42</span>.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">subtitles</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SubTitleData <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">text</span> : <span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">start</span> : <span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">duration</span> : <span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">end</span> : <span style="color: #0066CC;">Number</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SubTitleData<span style="color: #66cc66;">&#40;</span>inText : <span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>,inStart : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>,inDuration : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>,inEnd : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">text</span> = inText;
			<span style="color: #0066CC;">start</span> = inStart;
			<span style="color: #0066CC;">duration</span> = inDuration;
			<span style="color: #0066CC;">end</span> = inEnd;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">toString</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: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;nl.inlet42.data.subtitles.SubTitleData&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>Update:</strong> Thanks to Tiago for the update.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.base42.nl/2009/as3-srt-subtitle-parser/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Recursion for Flash</title>
		<link>http://blog.base42.nl/2009/recursion-for-the-timeline-in-flash/</link>
		<comments>http://blog.base42.nl/2009/recursion-for-the-timeline-in-flash/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 07:15:47 +0000</pubDate>
		<dc:creator>jankees</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.base42.nl/?p=835</guid>
		<description><![CDATA[This morning in the train I worked on a little script for recursion. I need this to update a timeline animation on the fly. With this script you get an Array with every DisplayObject on the currentframe in a DisplayObjectContainer (MovieClip, Sprite etc). package test &#123; import flash.display.DisplayObject; import flash.display.DisplayObjectContainer; &#160; /** * @author Jankees.van.Woezik [...]]]></description>
			<content:encoded><![CDATA[<p>This morning in the train I worked on a little script for recursion. I need this to update a timeline animation on the fly.</p>
<p>With this script you get an Array with every DisplayObject on the currentframe in a DisplayObjectContainer (MovieClip, Sprite etc).</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package test <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">DisplayObject</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">DisplayObjectContainer</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * @author Jankees.van.Woezik
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Recursion <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> childs : <span style="color: #0066CC;">Array</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getAllChilds<span style="color: #66cc66;">&#40;</span>inMC : DisplayObjectContainer<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">Array</span> <span style="color: #66cc66;">&#123;</span>
			childs = <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>;
			findChilds<span style="color: #66cc66;">&#40;</span>inMC<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">return</span> childs;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> findChilds<span style="color: #66cc66;">&#40;</span>inDisplayObjectContainer : DisplayObjectContainer,inCurrentDepth : uint = <span style="color: #cc66cc;">0</span><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> i : uint = inDisplayObjectContainer.<span style="color: #006600;">numChildren</span>;
			<span style="color: #000000; font-weight: bold;">var</span> child : DisplayObject;
&nbsp;
			<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span> i -- <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				child = inDisplayObjectContainer.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;
&nbsp;
				<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>child is DisplayObjectContainer<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					childs.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>child<span style="color: #66cc66;">&#41;</span>;
					findChilds<span style="color: #66cc66;">&#40;</span>DisplayObjectContainer<span style="color: #66cc66;">&#40;</span>inDisplayObjectContainer.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>, inCurrentDepth + <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>child is DisplayObject<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					childs.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>child<span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.base42.nl/2009/recursion-for-the-timeline-in-flash/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Slice images with a Matrix</title>
		<link>http://blog.base42.nl/2009/slice-images-with-a-matrix/</link>
		<comments>http://blog.base42.nl/2009/slice-images-with-a-matrix/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 08:43:58 +0000</pubDate>
		<dc:creator>jankees</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[Matrix]]></category>
		<category><![CDATA[Slice]]></category>

		<guid isPermaLink="false">http://blog.base42.nl/?p=716</guid>
		<description><![CDATA[For my current project I needed something to slice an image easily, first I tried to slice the image with a mask, but I soon found out that this much heavier than my current solution. Below is the end result I needed to have (the triangle is a big mask). // image = a MovieClip [...]]]></description>
			<content:encoded><![CDATA[<p>For my current project I needed something to slice an image easily, first I tried to slice the image with a mask, but I soon found out that this much heavier than my current solution.</p>
<p>Below is the end result I needed to have (the triangle is a big mask).<img class="alignnone size-full wp-image-719" title="Lukx Image Slice Example" src="http://blog.base42.nl/wp-content/uploads/lukxexample.jpg" alt="Lukx Image Slice Example" width="650" height="402" /></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// image = a MovieClip with an image</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// upper part</span>
<span style="color: #6699cc; font-weight: bold;">var</span> upperBitmapData<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span>image<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span>image<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
upperBitmapData<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span>image<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
mUpperBitmap = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span>upperBitmapData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>mUpperBitmap<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//lowerpart</span>
<span style="color: #6699cc; font-weight: bold;">var</span> lowerMatrix<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Matrix</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Matrix</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
lowerMatrix<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ty</span> = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000;">&#40;</span>image<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> 
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> lowerBitmapData<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span>image<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span>image<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
lowerBitmapData<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span>image<span style="color: #000066; font-weight: bold;">,</span>lowerMatrix<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
mLowerBitmap = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span>lowerBitmapData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
mLowerBitmap<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = ContentClip<span style="color: #000066; font-weight: bold;">.</span>MASK_HEIGHT <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>mLowerBitmap<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
image = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.base42.nl/2009/slice-images-with-a-matrix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>We are building an AS3 framework</title>
		<link>http://blog.base42.nl/2009/we-are-building-an-as3-framework/</link>
		<comments>http://blog.base42.nl/2009/we-are-building-an-as3-framework/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 09:31:32 +0000</pubDate>
		<dc:creator>jankees</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Inlet 42]]></category>

		<guid isPermaLink="false">http://blog.base42.nl/?p=512</guid>
		<description><![CDATA[Together with my colleague Patrick Brouwer, we are building an AS3 framework that we can reuse in a lot of situations. We bought VisDoc to create a good documentation of the project. When it&#8217;s ready I&#8217;ll try to do a post on what we did, and why. I really like the preloading mechanism we came [...]]]></description>
			<content:encoded><![CDATA[<p>Together with my colleague Patrick Brouwer, we are building an AS3 framework that we can reuse in a lot of situations.</p>
<p>We bought <a href="http://visiblearea.com/visdoc/">VisDoc</a> to create a good documentation of the project. When it&#8217;s ready I&#8217;ll try to do a post on what we did, and why. I really like the preloading mechanism we came up with.</p>
<p><img class="alignnone size-large wp-image-513" title="picture-15" src="http://blog.base42.nl/wp-content/uploads/picture-15-500x316.png" alt="picture-15" width="500" height="316" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.base42.nl/2009/we-are-building-an-as3-framework/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Betaling in Flash</title>
		<link>http://blog.base42.nl/2008/betaling-in-flash/</link>
		<comments>http://blog.base42.nl/2008/betaling-in-flash/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 15:24:18 +0000</pubDate>
		<dc:creator>jankees</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.base42.nl/?p=336</guid>
		<description><![CDATA[Een iDeal implementatie in Flash is lastiger dan je denkt.]]></description>
			<content:encoded><![CDATA[<p>Een iDeal implementatie in Flash is lastiger dan je denkt.</p>
<p><a href="http://blog.base42.nl/wp-content/uploads/photo.jpg"><img class="alignnone size-full wp-image-337" title="photo" src="http://blog.base42.nl/wp-content/uploads/photo.jpg" alt="" width="500" height="375" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.base42.nl/2008/betaling-in-flash/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

