<?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>Ryan Bosinger &#187; Actionscript</title>
	<atom:link href="http://ryanbosinger.com/blog/category/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://ryanbosinger.com/blog</link>
	<description>things I learn, as I learn them</description>
	<lastBuildDate>Fri, 18 May 2012 20:45:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Calling namespaced Javascript from Flash with ExternalInterface&#8230;</title>
		<link>http://ryanbosinger.com/blog/2011/calling-namespaced-javascript-from-flash-with-externalinterface/</link>
		<comments>http://ryanbosinger.com/blog/2011/calling-namespaced-javascript-from-flash-with-externalinterface/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 06:27:40 +0000</pubDate>
		<dc:creator>rbosinger</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://ryanbosinger.com/blog/?p=409</guid>
		<description><![CDATA[Edit: This just seemed to eventually start working for me out nowhere. I hate when that happens. If you&#8217;re having the same problem I recommend you go have a beer and come back to it later. This is pissing me off. I have some Javascript that looks like this: var boz = &#123; thing: function&#40;val&#41; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Edit:</strong> This just seemed to eventually start working for me out nowhere.  I hate when that happens.  If you&#8217;re having the same problem I recommend you go have a beer and come back to it later.</p>

<p>This is pissing me off.  I have some Javascript that looks like this:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> boz <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
      thing<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>val<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>val<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>




<p>I want to call it from Flash using ExternalInterface like this:</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">ExternalInterface.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;boz.thing&quot;</span>, <span style="color: #ff0000;">&quot;what the shit!?&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>




<p>&#8230;but that doesn&#8217;t work.</p>

<p>Somebody asked about this on StackOverflow (<a href="http://stackoverflow.com/questions/2230869/calling-a-namespaced-javascript-function-from-flash" target="_blank">here</a>) and in the accepted answer the guy says the code is basically just eval&#8217;d so it&#8217;ll work just fine.  He has an example like this:</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">ExternalInterface.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;function (foo) { alert(foo); return true; }&quot;</span>,<span style="color: #ff0000;">&quot;test&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>




<p>That doesn&#8217;t work either.  I can only seem to get it to work with global function calls.  Am I missing something?  There certainly doesn&#8217;t seem to any examples of calling namespaced Javascript from Flash out there.</p>

<p>I&#8217;ll post back if I find out what&#8217;s going on.</p>

</p>Piece.</p>]]></content:encoded>
			<wfw:commentRss>http://ryanbosinger.com/blog/2011/calling-namespaced-javascript-from-flash-with-externalinterface/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash 10 + ExternalInterface + FileReference</title>
		<link>http://ryanbosinger.com/blog/2010/flash-10-externalinterface-filereference/</link>
		<comments>http://ryanbosinger.com/blog/2010/flash-10-externalinterface-filereference/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 18:13:28 +0000</pubDate>
		<dc:creator>rbosinger</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://ryanbosinger.com/blog/?p=367</guid>
		<description><![CDATA[If you try to call a function within Flash from Javascript and that function has the intention of calling a FileReferenceList.browse() it&#8217;s not going to work. It&#8217;s a security thing. You need to use an in-movie button. Even if you have the JS call a function which calls another function that calls FileReferenceList.browse() it&#8217;s still [...]]]></description>
			<content:encoded><![CDATA[<p>If you try to call a function within Flash from Javascript and that function has the intention of calling a FileReferenceList.browse() it&#8217;s not going to work.  It&#8217;s a security thing.  You need to use an in-movie button.  Even if you have the JS call a function which calls another function that calls FileReferenceList.browse() it&#8217;s still not going to let you do it.  I wasted some time figuring this out.  Just give up. </p>

<p>This guy had the same issue: <a href="http://kevinmusselman.com/blog/2009/01/multiple-file-upload-using-flash/">http://kevinmusselman.com/blog/2009/01/multiple-file-upload-using-flash/</a></p>]]></content:encoded>
			<wfw:commentRss>http://ryanbosinger.com/blog/2010/flash-10-externalinterface-filereference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash 9: Text fields and buttons don&#8217;t show up in browser</title>
		<link>http://ryanbosinger.com/blog/2008/flash-9-text-fields-and-buttons-dont-show-up-in-browser/</link>
		<comments>http://ryanbosinger.com/blog/2008/flash-9-text-fields-and-buttons-dont-show-up-in-browser/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 14:51:49 +0000</pubDate>
		<dc:creator>rbosinger</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://ryanbosinger.com/blog/?p=58</guid>
		<description><![CDATA[Problem: You publish your SWF from the Flash CS3 IDE and everything looks fine. You, or someone else checks out the SWF in a browser and although everything kind of works, certain elements like text fields and component buttons aren&#8217;t rendering properly! Solution: Sometimes certain revisions of the Flash 9 player behave differently than expected, [...]]]></description>
			<content:encoded><![CDATA[    <div class="problem-solution">
        <p class="problem">
            <strong>
                Problem:
            </strong>
        </p> 
        <blockquote>
            You publish your SWF from the Flash CS3 IDE and everything looks fine.  You, or someone else checks out the SWF in a browser and although everything kind of works, certain elements like text fields and component buttons aren&#8217;t rendering properly!
        </blockquote> 
        
        <p class="solution">
            <strong>
                Solution:
            </strong>
        </p>
        <blockquote>
            Sometimes certain revisions of the Flash 9 player behave differently than expected, but there is a way you can look into it.  Read on&#8230;
        </blockquote>
    </div>
<span id="more-58"></span>


<p>I actually just tried to recreate this, and I can&#8217;t.  All I know, is that on two particular occasions while working on moderate sized flash projects certain revisions of the flash player would fail to render some things properly (but not every time).  This kind of thing is very frustrating, and if you think it might be happening to you, this is what I suggest:</p>

<ul>
<li>Go here: <a href="http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_14266">http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_14266</a> and download the Flash Player 9 archive file (I had this problem with FP9).</li>
<li>Go here: <a href="http://www.adobe.com/support/flashplayer/downloads.html">http://www.adobe.com/support/flashplayer/downloads.html</a> and download the Flash uninstaller.</li>
<li>Uninstall Flash, install a different revision, and test your movie (in the browser).  In my case, revision 47 caused this problem, and sure enough anyone testing the movie that saw this problem had revision 47.  I haven&#8217;t been able to recreate this error by creating a new flash movie using components and viewing it with flash player rev 47, but there must have been some combination of things that the particular revision didn&#8217;t like.</li>
<li>If you find a revision that&#8217;s giving you problems, make sure to check for a more current one in your flash embed code.</li>
</ul>

<p>This is a screenshot of the unzipped folder containing all the different versions of Flash 9.  The ones ending in &#8220;win&#8221; would be for Firefox and Netscape, and the ones ending in &#8220;winax&#8221; are for IE (ActiveX).  There&#8217;s some linux and mac ones in there too.  I believe &#8220;SA&#8221; stands for standalone.  Play around.</p>
<a href='http://ryanbosinger.com/blog/wp-content/uploads/2008/10/screenhunter_02-oct-01-1045.gif'><img src="http://ryanbosinger.com/blog/wp-content/uploads/2008/10/screenhunter_02-oct-01-1045.gif" alt="Screenshot of Flash 9 archives" title="screenhunter_02-oct-01-1045" width="500" height="691" class="alignnone size-full wp-image-59" /></a>

]]></content:encoded>
			<wfw:commentRss>http://ryanbosinger.com/blog/2008/flash-9-text-fields-and-buttons-dont-show-up-in-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Save images from Flash to your server using ASP.NET webservices</title>
		<link>http://ryanbosinger.com/blog/2008/saving-images-with-net/</link>
		<comments>http://ryanbosinger.com/blog/2008/saving-images-with-net/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 18:29:38 +0000</pubDate>
		<dc:creator>rbosinger</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://ryanbosinger.com/blog/?p=42</guid>
		<description><![CDATA[Problem: You want to save an image from Flash to a server using Actionscript 3.0 and ASP.NET. Solution: Read this article! Note: This blog is hosted on a Linux based server that uses PHP, therefore I can&#8217;t show you a working example directly on this blog (unless anyone with a Windows based hosting account would [...]]]></description>
			<content:encoded><![CDATA[    <div class="problem-solution">
        <p class="problem">
            <strong>
                Problem:
            </strong>
        </p> 
        <blockquote>
You want to save an image from Flash to a server using Actionscript 3.0 and ASP.NET.
        </blockquote> 
        
        <p class="solution">
            <strong>
                Solution:
            </strong>
        </p>
        <blockquote>
            Read this article!
        </blockquote>
    </div>
<span id="more-42"></span>
<p>
<strong>Note: </strong>
This blog is hosted on a Linux based server that uses PHP, therefore I can&#8217;t show you a working example directly on this blog (unless anyone with a Windows based hosting account would like to host one for me?).  However, I can assure you this <em>does</em> work and you can download the files here and try it for yourself.
</p>

<p class="download">
<a href="/blog/downloads/FlashBitmapSave.zip">
Download &#8220;FlashBitmapSave.zip&#8221;
</a>
<p>
<div class="google_ads_01">
<script type="text/javascript"><!--
google_ad_client = "pub-1962502741893893";
/* 468x60, created 5/27/08 */
google_ad_slot = "8820555819";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<h3>Get this thing running</h3>
<span><em>&#8230;or just take a look at the code/explanation&#8230;</em></span><br/>
<p>
<a href='http://ryanbosinger.com/blog/wp-content/uploads/2008/09/screenhunter_06-sep-18-1021.gif'><img src="http://ryanbosinger.com/blog/wp-content/uploads/2008/09/screenhunter_06-sep-18-1021.gif" alt="" title="screenhunter_06-sep-18-1021" width="429" height="86" class="alignnone size-full wp-image-45" /></a>
</p>

<p>Open the downloaded website in Visual Studio 2008 or Visual Web Developer Express 2008.  2005 versions should be fine as well.</p>

<p>
<a href='http://ryanbosinger.com/blog/wp-content/uploads/2008/09/screenhunter_07-sep-18-1021.gif'><img src="http://ryanbosinger.com/blog/wp-content/uploads/2008/09/screenhunter_07-sep-18-1021.gif" alt="" title="screenhunter_07-sep-18-1021" class="alignnone size-full wp-image-44" /></a>
</p>

<p>Run it.</p>

<p>
<a href='http://ryanbosinger.com/blog/wp-content/uploads/2008/09/screenhunter_08-sep-18-1046.gif'><img src="http://ryanbosinger.com/blog/wp-content/uploads/2008/09/screenhunter_08-sep-18-1046.gif" alt="" title="screenhunter_08-sep-18-1046" class="alignnone size-full wp-image-46" /></a>
</p>

<p>The default page should come up in your browser.  You&#8217;ll see my example Flash app.  Draw a picture and click &#8220;save to server&#8221; to &#8211; of course &#8211; save a JPEG version of your drawing from Flash.</p>

<p><strong>Note:</strong> Saved JPEGs will be assigned a random GUID as a filename and saved directly to the root of your C: drive.  You can modify the path in App_Code/Service.vb.  If you need to know more about that aspect of it, I would continue reading the rest of this post.</p>

<p><strong>If the flash app comes up but gives you the message &#8220;<em>webservice failed to initialize&#8230;</em>&#8221; then:</strong></p>

<p>Click on the root of the project in your solution explorer.</p>
<a href='http://ryanbosinger.com/blog/wp-content/uploads/2008/09/screenhunter_09-sep-18-1648.gif'><img src="http://ryanbosinger.com/blog/wp-content/uploads/2008/09/screenhunter_09-sep-18-1648.gif" alt="" title="screenhunter_09-sep-18-1648" class="alignnone size-full wp-image-47" /></a>
<br/><br/>
<p>In the properties panel below, take a look at your Virtual Path.</p>
<a href='http://ryanbosinger.com/blog/wp-content/uploads/2008/09/screenhunter_10-sep-18-1649.gif'><img src="http://ryanbosinger.com/blog/wp-content/uploads/2008/09/screenhunter_10-sep-18-1649.gif" alt="" title="screenhunter_10-sep-18-1649" class="alignnone size-full wp-image-48" /></a>
<br/><br/>
<p>It should only have a &#8220;/&#8221; in it.</p>
<a href='http://ryanbosinger.com/blog/wp-content/uploads/2008/09/screenhunter_11-sep-18-1649.gif'><img src="http://ryanbosinger.com/blog/wp-content/uploads/2008/09/screenhunter_11-sep-18-1649.gif" alt="" title="screenhunter_11-sep-18-1649"  class="alignnone size-full wp-image-49" /></a>
<br/><br/>
<p>Try it again.</p>

<div class="google_ads_01">
<script type="text/javascript"><!--
google_ad_client = "pub-1962502741893893";
/* 468x60, created 5/27/08 */
google_ad_slot = "8820555819";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>

<h3>The process</h3>

<ul>
<li>Take a BitmapData object in Flash, and convert it to a ByteArray object using the JPGEncoder class (or, in my example, the Asynchronous JPEG Encoder class).</li>
<li>Take that ByteArray and Base64 encode it.  We do this so that Actionscript and the .NET back-end will be speaking the same language.  If we were using Flex and remoting software like WebORB, this type of conversion would likely happen automatically when sending or receiving a ByteArray object to/from Actionscript or .NET.  But for this one-off scenario, doing it ourselves isn&#8217;t a big deal.</li>
<li>Use a third party AS3 webservice class to send the encoded ByteArray to our .NET webservice.</li>
<li>Our .NET webservice unencodes the ByteArray into its own form of ByteArray, creates a random file name using a GUID, and then saves the raw binary information to a .jpg file.</li>
</ul>

<h3>Some extra stuff you will need</h3>

<ul>
   <li>
		<strong>
			<a href="http://dynamicflash.com/goodies/base64/">
				Base64 encoder/decoder class
			</a>
		</strong>
		<br/>
		This class from Dynamic Flash will be used to encode our ByteArray to Base64.
   </li>
   <li>
		<strong>
			<a href="http://www.wellconsidered.be/blog/as3-webservice-component/">
				WebService component
			</a>
		</strong>
		<br/>
		Adobe left the WebService classes out of Flash CS3.  wellconsidered made their own.  This is how we&#8217;ll be communicating with the server.  This download is available as a .swc and needs to be dropped
		into your .fla to work.
   </li>
   <li>
		<strong>
			<a href="http://blog.paranoidferret.com/index.php/2007/12/11/flex-tutorial-an-asynchronous-jpeg-encoder/">
				Asynchronous JPEG Encoder
			</a>
		</strong>
		<br/>
		In my example I use the Asynchronous JPEG Encoder.  You could also use Adobe&#8217;s regular JPEG encode available in the <a href="http://code.google.com/p/as3corelib/">AS3 CoreLib</a>.
   </li>
</ul>

<div class="google_ads_01">
<script type="text/javascript"><!--
google_ad_client = "pub-1962502741893893";
/* 468x60, created 5/27/08 */
google_ad_slot = "8820555819";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>

<h3>The Code</h3>

<p>
Now I&#8217;m just going to post the code.  I did my best to comment the code thoroughly, but I&#8217;m not going to go through it line by line in this post.  I&#8217;ll assume that if you&#8217;re in need of saving bitmap information from flash to a server using .NET, that most of what&#8217;s going on you already understand and maybe just needed an example to help you along.  So here ya go!
</p>

<h4>The actionscript 3.0 code:</h4>


<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Bitmap</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">BitmapData</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.<span style="color: #004993;">TextField</span>;
        <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #000000; font-weight: bold;">*</span>;
        <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #000000; font-weight: bold;">*</span>;
        <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">MovieClip</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span>.<span style="color: #004993;">ByteArray</span>;
&nbsp;
	<span style="color: #009900;">// We'll be sending a ByteArray encoded as Base64, and then decoding it on the .NET side.</span>
	<span style="color: #009900;">// http://dynamicflash.com/goodies/base64/</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.dynamicflash.util.Base64;
&nbsp;
	<span style="color: #009900;">// be.wellconsidered classes give us an easy means to communicate with webservices.</span>
	<span style="color: #009900;">// The extension needs to be installed and the component then dropped into your .FLA.</span>
	<span style="color: #009900;">// You'll see a component called &quot;Service&quot; in the library of the example .FLA.</span>
	<span style="color: #009900;">// http://www.wellconsidered.be/blog/as3-webservice-component/</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> be.wellconsidered.services.WebService;
	<span style="color: #0033ff; font-weight: bold;">import</span> be.wellconsidered.services.Operation;
	<span style="color: #0033ff; font-weight: bold;">import</span> be.wellconsidered.services.events.OperationEvent;
	<span style="color: #0033ff; font-weight: bold;">import</span> be.wellconsidered.services.events.WebServiceEvent;
&nbsp;
	<span style="color: #009900;">// com.pfp includes classes for the Asynchronous JPEG encoder.  There is also a JPEG encoder</span>
	<span style="color: #009900;">// in Adobe's CoreLib (http://code.google.com/p/as3corelib/), but because this one is asynchronous it allows to </span>
	<span style="color: #009900;">// monitor the rendering of the jpeg and therefore create a progress bar.  It is also essential when rendering larger</span>
	<span style="color: #009900;">// bitmaps, otherwise Flash could time out during the processing.</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.pfp.events.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.pfp.utils.<span style="color: #000000; font-weight: bold;">*</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> FlashBitmapSave extends <span style="color: #004993;">MovieClip</span>
    <span style="color: #000000;">&#123;</span>
	<span style="color: #009900;">// we create our WebService object.  Remember to include &quot;?wsdl&quot; in the URL.</span>
	<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> wsMainService<span style="color: #000000; font-weight: bold;">:</span>WebService = <span style="color: #0033ff; font-weight: bold;">new</span> WebService<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;/Service.asmx?wsdl&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
                <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> FlashBitmapSave<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                        mcDrawingBoard.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_DOWN</span>, mcDrawingBoard_MouseDown<span style="color: #000000;">&#41;</span>;
			btnSaveToServer.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, btnSaveToServer_Click<span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">// the listener on our webservice will let us know if there's a problem with the webservice,</span>
			<span style="color: #009900;">// if the url is wrong, if the service is down, etc.</span>
			wsMainService.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>WebServiceEvent.INITFAILED, wsMainService_InitFailed<span style="color: #000000;">&#41;</span>;
                <span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900;">// **** functions for the drawing pad **** //</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> mcDrawingBoard_MouseDown<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			mcDrawingBoard.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_MOVE</span>, mcDrawingBoard_MouseMove<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_UP</span>, stage_MouseUp<span style="color: #000000;">&#41;</span>;
			mcDrawingBoard.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span>mcDrawingBoard.<span style="color: #004993;">mouseX</span>, mcDrawingBoard.<span style="color: #004993;">mouseY</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> mcDrawingBoard_MouseMove<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			mcDrawingBoard.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">lineStyle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span>, 0x000000<span style="color: #000000;">&#41;</span>;
			mcDrawingBoard.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">lineTo</span><span style="color: #000000;">&#40;</span>mcDrawingBoard.<span style="color: #004993;">mouseX</span>, mcDrawingBoard.<span style="color: #004993;">mouseY</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> stage_MouseUp<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			mcDrawingBoard.<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_MOVE</span>, mcDrawingBoard_MouseMove<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900;">// ************************************** //</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> btnSaveToServer_Click<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> bmdSnapshot<span style="color: #000000; 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>mcDrawingBoard.<span style="color: #004993;">width</span>, mcDrawingBoard.<span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">// take a snapshot of what was drawn in &quot;mcDrawingBoard&quot;</span>
			bmdSnapshot.<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span>mcDrawingBoard<span style="color: #000000;">&#41;</span>;
&nbsp;
			saveImage<span style="color: #000000;">&#40;</span>bmdSnapshot<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> wsMainService_InitFailed<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span>WebServiceEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">log</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Webservice failed to initialize.&quot;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> saveImage<span style="color: #000000;">&#40;</span>bmdSend<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">// create a new JPEGAsyncEncoder.  80 is the JPEG quality.</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> jpgEncoder<span style="color: #000000; font-weight: bold;">:</span>JPEGAsyncEncoder = <span style="color: #0033ff; font-weight: bold;">new</span> JPEGAsyncEncoder<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">// encodes 400 pixels before sending out a ProgressEvent.  That means every 400 pixels the CPU has a chance to &quot;breath&quot;</span>
			<span style="color: #009900;">// and process some other code.  </span>
			jpgEncoder.PixelsPerIteration = <span style="color: #000000; font-weight:bold;">400</span>;
&nbsp;
			jpgEncoder.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>JPEGAsyncCompleteEvent.JPEGASYNC_COMPLETE, jpgEncoder_Complete<span style="color: #000000;">&#41;</span>;
			jpgEncoder.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">ProgressEvent</span>.<span style="color: #004993;">PROGRESS</span>, jpgEncoder_Progress<span style="color: #000000;">&#41;</span>;
&nbsp;
			jpgEncoder.encode<span style="color: #000000;">&#40;</span>bmdSend<span style="color: #000000;">&#41;</span>;			
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> jpgEncoder_Complete<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span>JPEGAsyncCompleteEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> jpgByteArray<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">ByteArray</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">ByteArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">// put the raw image data we got back from the encoder into our ByteArray</span>
			jpgByteArray = e.ImageData;
&nbsp;
			sendToServer<span style="color: #000000;">&#40;</span>jpgByteArray<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> jpgEncoder_Progress<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">ProgressEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">log</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;encoding... &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">Math</span>.<span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">bytesLoaded</span> <span style="color: #000000; font-weight: bold;">/</span> e.<span style="color: #004993;">bytesTotal</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> sendToServer<span style="color: #000000;">&#40;</span>byteArray<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">ByteArray</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> opJPEGSaver<span style="color: #000000; font-weight: bold;">:</span>Operation = <span style="color: #0033ff; font-weight: bold;">new</span> Operation<span style="color: #000000;">&#40;</span>wsMainService<span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">// unfortunately, I don't think the WebService class we're using has a working ProgressEvent.</span>
			<span style="color: #009900;">// if I'm wrong, please let me know!</span>
			opJPEGSaver.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>OperationEvent.<span style="color: #004993;">COMPLETE</span>, opJPEGSaver_Complete<span style="color: #000000;">&#41;</span>;
			opJPEGSaver.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>OperationEvent.FAILED, opJPEGSaver_Failed<span style="color: #000000;">&#41;</span>;	
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> strEncodedString<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">String</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">// the Base64 class is static, so we can just call it using Base64.&lt;whatever&gt;</span>
			strEncodedString = Base64.encodeByteArray<span style="color: #000000;">&#40;</span>byteArray<span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">// send the encoded bytes to our webservice function we called &quot;SaveJPEG&quot;.</span>
			opJPEGSaver.SaveJPEG<span style="color: #000000;">&#40;</span>strEncodedString<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> opJPEGSaver_Complete<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span>OperationEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">log</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;ByteArray successfully sent to server.&quot;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> opJPEGSaver_Failed<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span>OperationEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">log</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Error sending ByteArray to server.&quot;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">log</span><span style="color: #000000;">&#40;</span>strLog<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">// my own way of tracing to the textfield txtTrace -- as you can see.</span>
			<span style="color: #009900;">// not an important part of anything going on here.</span>
			txtTrace.<span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span>strLog <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</span>;
			traceScrollBar.scrollTarget = txtTrace;
			txtTrace.<span style="color: #004993;">scrollV</span> = txtTrace.<span style="color: #004993;">numLines</span>;
		<span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>




<h4>The VB.NET code:</h4>


<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Web</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">Services</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">Services</span>.<span style="color: #0000FF;">Protocols</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">IO</span>
&nbsp;
<span style="color: #008080; font-style: italic;">' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.</span>
<span style="color: #008080; font-style: italic;">' &lt;System.Web.Script.Services.ScriptService()&gt; _</span>
&lt;WebService<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Namespace</span>:<span style="color: #008000;">=</span><span style="color: #808080;">&quot;http://tempuri.org/&quot;</span><span style="color: #000000;">&#41;</span>&gt; _
&lt;WebServiceBinding<span style="color: #000000;">&#40;</span>ConformsTo:<span style="color: #008000;">=</span>WsiProfiles.<span style="color: #0000FF;">BasicProfile1_1</span><span style="color: #000000;">&#41;</span>&gt; _
&lt;Global.<span style="color: #0000FF;">Microsoft</span>.<span style="color: #0000FF;">VisualBasic</span>.<span style="color: #0000FF;">CompilerServices</span>.<span style="color: #0000FF;">DesignerGenerated</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>&gt; _
<span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Class</span> Service
     <span style="color: #0600FF;">Inherits</span> System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">Services</span>.<span style="color: #0000FF;">WebService</span>
&nbsp;
&nbsp;
    &lt;WebMethod<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>&gt; _
    <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Function</span> SaveJPEG<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> strJPEG <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'saves an uploaded photo and returns a unique name reference</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> BinaryContent <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Byte</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> Convert.<span style="color: #0000FF;">FromBase64String</span><span style="color: #000000;">&#40;</span>strJPEG<span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;">Try</span>
            <span style="color: #008080; font-style: italic;">'generate a unique name (GUID) for the filename</span>
            <span style="color: #0600FF;">Dim</span> strFileName <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> System.<span style="color: #0000FF;">Guid</span>.<span style="color: #0000FF;">NewGuid</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;n&quot;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #008080; font-style: italic;">'MAKE SURE to change the save path!</span>
            <span style="color: #0600FF;">Dim</span> fStream <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> FileStream<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;C:\&quot;</span> <span style="color: #008000;">+</span> strFileName <span style="color: #008000;">+</span> <span style="color: #808080;">&quot;.jpg&quot;</span>, FileMode.<span style="color: #0000FF;">CreateNew</span><span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">Dim</span> bw <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> BinaryWriter<span style="color: #000000;">&#40;</span>fStream<span style="color: #000000;">&#41;</span>
&nbsp;
            bw.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span>BinaryContent<span style="color: #000000;">&#41;</span>
            bw.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
            fStream.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">'return the filename for use in Flash</span>
            <span style="color: #FF8000;">Return</span> strFileName
&nbsp;
        <span style="color: #0600FF;">Catch</span> ex <span style="color: #FF8000;">As</span> Exception
&nbsp;
            <span style="color: #FF8000;">Return</span> ex.<span style="color: #0000FF;">Message</span>
&nbsp;
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Try</span>
&nbsp;
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span>
&nbsp;
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></pre></div></div>


]]></content:encoded>
			<wfw:commentRss>http://ryanbosinger.com/blog/2008/saving-images-with-net/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Actionscript 3.0:  Scale Object from Center Point</title>
		<link>http://ryanbosinger.com/blog/2008/actionscript-30-scale-object-from-center-point/</link>
		<comments>http://ryanbosinger.com/blog/2008/actionscript-30-scale-object-from-center-point/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 19:52:29 +0000</pubDate>
		<dc:creator>rbosinger</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://ryanbosinger.com/blog/?p=35</guid>
		<description><![CDATA[Note: This is almost exactly the same solution I posted earlier for rotating an object around its center point (Actionscript 3.0: Rotate Around Center Point). I thought I&#8217;d post this slightly altered solution for people who need it. Problem: You need to scale a movieclip/sprite from its center point, but its registration point is at [...]]]></description>
			<content:encoded><![CDATA[<p>
<em>Note: This is almost exactly the same solution I posted earlier for rotating an object around its center point (<a href="/blog/2008/actionscript-30-rotate-around-center-point/">Actionscript 3.0: Rotate Around Center Point</a>).  I thought I&#8217;d post this slightly altered solution for people who need it.</em>
</p>

    <div class="problem-solution">
        <p class="problem">
            <strong>
                Problem:
            </strong>
        </p> 
        <blockquote>
You need to scale a movieclip/sprite from its center point, but its registration point is at (0,0) and you can&#8217;t and/or don&#8217;t feel like putting this object in the center of a container movieclip and rotating that
        </blockquote> 
        
        <p class="solution">
            <strong>
                Solution:
            </strong>
        </p>
        <blockquote>
            TCBWMO (Take care of business with the matrix object).
        </blockquote>
    </div>

<span id="more-35"></span>
<p>
Here&#8217;s the function:
</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> scaleFromCenter<span style="color: #000000;">&#40;</span>ob<span style="color: #000000; font-weight: bold;">:*</span>, sx<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, sy<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, ptScalePoint<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Point</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> 
	<span style="color: #6699cc; font-weight: bold;">var</span> m<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Matrix</span>=ob.<span style="color: #004993;">transform</span>.<span style="color: #004993;">matrix</span>;
	m.<span style="color: #004993;">tx</span> <span style="color: #000000; font-weight: bold;">-</span>= ptScalePoint.<span style="color: #004993;">x</span>;
	m.<span style="color: #004993;">ty</span> <span style="color: #000000; font-weight: bold;">-</span>= ptScalePoint.<span style="color: #004993;">y</span>;
	m.<span style="color: #004993;">scale</span><span style="color: #000000;">&#40;</span>sx, sy<span style="color: #000000;">&#41;</span>;
	m.<span style="color: #004993;">tx</span> <span style="color: #000000; font-weight: bold;">+</span>= ptScalePoint.<span style="color: #004993;">x</span>;
	m.<span style="color: #004993;">ty</span> <span style="color: #000000; font-weight: bold;">+</span>= ptScalePoint.<span style="color: #004993;">y</span>;
	ob.<span style="color: #004993;">transform</span>.<span style="color: #004993;">matrix</span> = m;
<span style="color: #000000;">&#125;</span></pre></div></div>




<div class="google_ads_01">
<script type="text/javascript"><!--
google_ad_client = "pub-1962502741893893";
/* 468x60, created 5/27/08 */
google_ad_slot = "8820555819";
google_ad_width = 468;
google_ad_height = 60;
//-->
// --&gt;</script>
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
</div>

<p>
Now to make this work, you could call it like this:
</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900;">//this will create a point object at the center of the display object</span>
ptRotationPoint = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>mcPhoto.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> mcPhoto.<span style="color: #004993;">width</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>, mcPhoto.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> mcPhoto.<span style="color: #004993;">height</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
<span style="color: #009900;">//call the function and pass in the object to be rotated, the amount to scale X and Y (sx, sy), and the point object we created</span>
scaleFromCenter<span style="color: #000000;">&#40;</span>mcPhoto, <span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000; font-weight:bold;">2</span>, ptScalePoint<span style="color: #000000;">&#41;</span>;</pre></div></div>




<p>
In this example we&#8217;re subbing in &#8220;2&#8243; for both the <em>sx</em> and <em>sy</em> values.  This will scale our image to twice its size.  If you want to scale down, use numbers lower than 1.
</p>]]></content:encoded>
			<wfw:commentRss>http://ryanbosinger.com/blog/2008/actionscript-30-scale-object-from-center-point/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Flash/Actionscript: Innaccurate math results</title>
		<link>http://ryanbosinger.com/blog/2008/flashactionscript-innaccurate-math-results/</link>
		<comments>http://ryanbosinger.com/blog/2008/flashactionscript-innaccurate-math-results/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 18:10:45 +0000</pubDate>
		<dc:creator>rbosinger</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://ryanbosinger.com/blog/?p=34</guid>
		<description><![CDATA[Problem: You&#8217;re working some math equations with Actionscript and tracing the results when you notice some results are off by a very small value. output: 2 2.1 2.2 2.3 2.4 2.5000000001 2.6 2.7000000001 2.8 2.9 3 Solution: This is called a floating point error and is apparently a normal computing error that affects all aspects [...]]]></description>
			<content:encoded><![CDATA[<div class="problem-solution">
    <p class="problem">
        <strong>
            Problem:
        </strong>
    </p> 
    <blockquote>
You&#8217;re working some math equations with Actionscript and tracing the results when you notice some results are off by a very small value.
<br />
<em><strong>output:</strong></em>
<pre>
2
2.1
2.2
2.3
2.4
2.5000000001
2.6
2.7000000001
2.8
2.9
3
</pre>
    </blockquote> 
    
    <p class="solution">
        <strong>
            Solution:
        </strong>
    </p>
    <blockquote>
This is called a <em>floating point error</em> and is apparently a normal computing error that affects all aspects of computing, not just flash.   You can fix this by running the values through the <em>correctFloatingPointError</em> function I&#8217;ve posted below.
    </blockquote>
</div>

<span id="more-34"></span>
<p>
I originally found this information/code on a post called <a href="http://www.zeuslabs.us/2007/01/30/flash-floating-point-number-errors/">Floating-point errors got you down?</a>
</p>

<div class="google_ads_01">
<script type="text/javascript"><!--
google_ad_client = "pub-1962502741893893";
/* 468x60, created 5/27/08 */
google_ad_slot = "8820555819";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>

<p>
I won&#8217;t repeat everything I read there, you can check that out yourself.  However, I thought I would re-post this information with the heading &#8220;Innaccurate math results&#8221; because that&#8217;s what I had been searching for before I realized I was experiencing a floating point error.  Anyway, here&#8217;s the code:
</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #3f5fbf;">/**
 * Corrects errors caused by floating point math.
 */</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> correctFloatingPointError<span style="color: #000000;">&#40;</span>number<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, precision<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #009900;">//default returns (10000 * number) / 10000</span>
	<span style="color: #009900;">//should correct very small floating point errors</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> correction<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span>, precision<span style="color: #000000;">&#41;</span>;
	<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">Math</span>.<span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span>correction <span style="color: #000000; font-weight: bold;">*</span> number<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> correction;
<span style="color: #000000;">&#125;</span>
<span style="color: #3f5fbf;">/**
 * Tests if two numbers are &lt;em&gt;almost&lt;/em&gt; equal.
 */</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> fuzzyEquals<span style="color: #000000;">&#40;</span>number1<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, number2<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, precision<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> difference<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = number1 <span style="color: #000000; font-weight: bold;">-</span> number2;
	<span style="color: #6699cc; font-weight: bold;">var</span> range<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span>, <span style="color: #000000; font-weight: bold;">-</span>precision<span style="color: #000000;">&#41;</span>;
	<span style="color: #009900;">//default check:</span>
	<span style="color: #009900;">//0.00001 &lt;difference&gt; -0.00001</span>
	<span style="color: #0033ff; font-weight: bold;">return</span> difference <span style="color: #000000; font-weight: bold;">&lt;</span>range <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> difference<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">-</span>range;
<span style="color: #000000;">&#125;</span>
<span style="color: #3f5fbf;">/*
Copyright (c) 2007 Josh Tynjala
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the &quot;Software&quot;), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/</span></pre></div></div>




]]></content:encoded>
			<wfw:commentRss>http://ryanbosinger.com/blog/2008/flashactionscript-innaccurate-math-results/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Actionscript 3.0:  Rotate Around Center Point</title>
		<link>http://ryanbosinger.com/blog/2008/actionscript-30-rotate-around-center-point/</link>
		<comments>http://ryanbosinger.com/blog/2008/actionscript-30-rotate-around-center-point/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 15:06:53 +0000</pubDate>
		<dc:creator>rbosinger</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://ryanbosinger.com/blog/?p=32</guid>
		<description><![CDATA[Problem: You need to rotate a movieclip/sprite around it&#8217;s center point, but its registration point is at (0,0) and you can&#8217;t and/or don&#8217;t feel like putting this object in the center of a container movieclip and rotating that. Solution: Use the transform matrix and show it who&#8217;s boss. If you want to get this done [...]]]></description>
			<content:encoded><![CDATA[<div class="problem-solution">
    <p class="problem">
        <strong>
            Problem:
        </strong>
    </p> 
    <blockquote>
You need to rotate a movieclip/sprite around it&#8217;s center point, but its registration point is at (0,0) and you can&#8217;t and/or don&#8217;t feel like putting this object in the center of a container movieclip and rotating that.
    </blockquote> 
    
    <p class="solution">
        <strong>
            Solution:
        </strong>
    </p>
    <blockquote>
Use the transform matrix and show it who&#8217;s boss.
    </blockquote>
</div>

<p>
If you want to get this done simply and quickly, you can use this rotateAroundCenter function:
</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"> <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> rotateAroundCenter <span style="color: #000000;">&#40;</span>ob<span style="color: #000000; font-weight: bold;">:*</span>, angleDegrees<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, ptRotationPoint<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Point</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> m<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Matrix</span>=ob.<span style="color: #004993;">transform</span>.<span style="color: #004993;">matrix</span>;
      m.<span style="color: #004993;">tx</span> <span style="color: #000000; font-weight: bold;">-</span>= ptRotationPoint.<span style="color: #004993;">x</span>;
      m.<span style="color: #004993;">ty</span> <span style="color: #000000; font-weight: bold;">-</span>= ptRotationPoint.<span style="color: #004993;">y</span>;
      m.<span style="color: #004993;">rotate</span> <span style="color: #000000;">&#40;</span>angleDegrees<span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
      m.<span style="color: #004993;">tx</span> <span style="color: #000000; font-weight: bold;">+</span>= ptRotationPoint.<span style="color: #004993;">x</span>;
      m.<span style="color: #004993;">ty</span> <span style="color: #000000; font-weight: bold;">+</span>= ptRotationPoint.<span style="color: #004993;">y</span>;
      ob.<span style="color: #004993;">transform</span>.<span style="color: #004993;">matrix</span>=m;
 <span style="color: #000000;">&#125;</span></pre></div></div>




<span id="more-32"></span>

<p>
Now to make this work, you could call it like this:
</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900;">//this will create a point object at the center of the display object</span>
ptRotationPoint = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>mcPhoto.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> mcPhoto.<span style="color: #004993;">width</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>, mcPhoto.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">+</span>mcPhoto.<span style="color: #004993;">height</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
<span style="color: #009900;">//call the function and pass in the object to be rotated, the amount in degrees, and the point object we created</span>
rotateAroundCenter<span style="color: #000000;">&#40;</span>mcPhoto, <span style="color: #000000; font-weight:bold;">90</span>, ptRotationPoint<span style="color: #000000;">&#41;</span>;</pre></div></div>




<div class="google_ads_01">
<script type="text/javascript"><!--
google_ad_client = "pub-1962502741893893";
/* 468x60, created 5/27/08 */
google_ad_slot = "8820555819";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>

<p>
There you go, that should work.  If you want to take it further, Jack Doyle at <a href="http://www.greensock.com">Greensock.com</a> (author of <em>TweenLite</em>) wrote an amazing class called <a href="http://blog.greensock.com/transformmatrixproxy/">TransformMatrixProxy</a> which will allow you to easily do all types of transformations (including rotation and skewing) based on the registration point you specify.  Oh, and you can tween these properties as well&#8230; hell yeah&#8230;
</p>

I haven&#8217;t tried it out myself yet, but the demo works great and I&#8217;m sure it&#8217;s a really great tool.  <a href="http://blog.greensock.com/transformmatrixproxy/">Go check it out.</a>

<a href='http://ryanbosinger.com/blog/wp-content/uploads/2008/07/screenhunter_02-jul-21-1058.gif'><img src="http://ryanbosinger.com/blog/wp-content/uploads/2008/07/screenhunter_02-jul-21-1058.gif" alt="A screen shot of the TransformMatrixProxy demo at greensock.com" title="Screenshot-TransformMatrixProxy-Demo" class="aligncenter size-full wp-image-33" /></a>
]]></content:encoded>
			<wfw:commentRss>http://ryanbosinger.com/blog/2008/actionscript-30-rotate-around-center-point/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Actionscript 3: Event.target returns children of movieclip</title>
		<link>http://ryanbosinger.com/blog/2008/actionscript-3-eventtarget-returns-children-of-movieclip/</link>
		<comments>http://ryanbosinger.com/blog/2008/actionscript-3-eventtarget-returns-children-of-movieclip/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 18:21:59 +0000</pubDate>
		<dc:creator>rbosinger</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://ryanbosinger.com/blog/2008/actionscript-3-eventtarget-returns-children-of-movieclip/</guid>
		<description><![CDATA[Problem: You&#8217;ve added a listener to a movieclip, but the target returned is another movieclip or sprite within that movieclip. Solution: myMovieclip.mouseChildren = false; Yeah, that&#8217;s all. Now the movieclip you added the listener to will be the only thing returned as the target of an event. If you want a little more proof before [...]]]></description>
			<content:encoded><![CDATA[<div class="problem-solution">
    <p class="problem">
        <strong>
            Problem:
        </strong>
    </p> 
    <blockquote>
        You&#8217;ve added a listener to a movieclip, but the target returned is another movieclip or sprite within that movieclip.
    </blockquote> 
    
    <p class="solution">
        <strong>
            Solution:
        </strong>
    </p>
    <blockquote>


<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">myMovieclip.<span style="color: #004993;">mouseChildren</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;</pre></div></div>



    </blockquote>
</div>

<span id="more-21"></span>
<p>
Yeah, that&#8217;s all.  Now the movieclip you added the listener to will be the only thing returned as the target of an event.  If you want a little more proof before you go through <em>all the trouble</em> to add that line of code, then check my example below:
</p>

<div style="text-align: center;">

<object width="470" height="300">
<param name="movie" value="http://www.ryanbosinger.com/blog/wp-content/uploads/2008/06/mousechildren.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<embed type="application/x-shockwave-flash" width="470" height="300" src="http://www.ryanbosinger.com/blog/wp-content/uploads/2008/06/mousechildren.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>

</div>

<p>
Here&#8217;s the code (on the timeline):
</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">blockLeft.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, clickBlock<span style="color: #000000;">&#41;</span>;
blockLeft.<span style="color: #004993;">buttonMode</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
blockLeft.<span style="color: #004993;">mouseChildren</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
&nbsp;
blockRight.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, clickBlock<span style="color: #000000;">&#41;</span>;
blockRight.<span style="color: #004993;">buttonMode</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
blockRight.<span style="color: #004993;">mouseChildren</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> clickBlock<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	txtTarget.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;e.target.name: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> e.<span style="color: #004993;">target</span>.<span style="color: #004993;">name</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>



]]></content:encoded>
			<wfw:commentRss>http://ryanbosinger.com/blog/2008/actionscript-3-eventtarget-returns-children-of-movieclip/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Resizing bitmap images with Actionscript 3.0</title>
		<link>http://ryanbosinger.com/blog/2008/resizing-bitmap-images-with-actionscript-30/</link>
		<comments>http://ryanbosinger.com/blog/2008/resizing-bitmap-images-with-actionscript-30/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 17:06:12 +0000</pubDate>
		<dc:creator>rbosinger</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://ryanbosinger.com/blog/2008/resizing-bitmap-images-with-actionscript-30/</guid>
		<description><![CDATA[Hey, I just did a quick experiment with bitmaps in AS3. Nothing fancy, I just loaded in an external JPEG, resized it into 3 different sizes and then drew them to stage. I&#8217;m sure someone can use this. For now, everything is hard-coded and the code is right in the .FLA. Maybe I&#8217;ll try and [...]]]></description>
			<content:encoded><![CDATA[<a href='http://ryanbosinger.com/blog/wp-content/uploads/2008/06/ostrich_ex.jpg'><img src="http://ryanbosinger.com/blog/wp-content/uploads/2008/06/ostrich_ex-300x127.jpg" alt="" title="Ostrich Image Resize" width="300" height="127" class="aligncenter size-medium wp-image-18" /></a>

<p>
Hey, I just did a quick experiment with bitmaps in AS3.  Nothing fancy, I just loaded in an external JPEG, resized it into 3 different sizes and then drew them to stage.  I&#8217;m sure someone can use this.  For now, everything is hard-coded and the code is right in the .FLA.  Maybe I&#8217;ll try and make a nice class out of this, although I&#8217;m sure there&#8217;s already one out there.  Anyway, check out the code or download the FLA.
</p>


<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> mediaLoader<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Loader</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Loader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #6699cc; font-weight: bold;">var</span> bmFullsize<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Bitmap</span>;
<span style="color: #6699cc; font-weight: bold;">var</span> bmHalfsize<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Bitmap</span>;
<span style="color: #6699cc; font-weight: bold;">var</span> bmThumbsize<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Bitmap</span>;
&nbsp;
mediaLoader.<span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;ostrich.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
mediaLoader.<span style="color: #004993;">contentLoaderInfo</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">COMPLETE</span>, resizeImages<span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> resizeImages<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	bmFullsize = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">target</span>.<span style="color: #004993;">content</span>.<span style="color: #004993;">bitmapData</span>.<span style="color: #004993;">clone</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
	bmHalfsize = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">target</span>.<span style="color: #004993;">content</span>.<span style="color: #004993;">bitmapData</span>.<span style="color: #004993;">clone</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
	bmThumbsize = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">target</span>.<span style="color: #004993;">content</span>.<span style="color: #004993;">bitmapData</span>.<span style="color: #004993;">clone</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
	bmFullsize.<span style="color: #004993;">width</span> = <span style="color: #000000; font-weight:bold;">300</span>;
	bmFullsize.<span style="color: #004993;">height</span> = <span style="color: #000000; font-weight:bold;">300</span>;
	bmFullsize.<span style="color: #004993;">smoothing</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
	bmHalfsize.<span style="color: #004993;">width</span> = <span style="color: #000000; font-weight:bold;">150</span>;
	bmHalfsize.<span style="color: #004993;">height</span> = <span style="color: #000000; font-weight:bold;">150</span>;
	bmHalfsize.<span style="color: #004993;">x</span> = bmFullsize.<span style="color: #004993;">width</span>;
	bmHalfsize.<span style="color: #004993;">smoothing</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
	bmThumbsize.<span style="color: #004993;">width</span> = <span style="color: #000000; font-weight:bold;">75</span>;
	bmThumbsize.<span style="color: #004993;">height</span> = <span style="color: #000000; font-weight:bold;">75</span>;
	bmThumbsize.<span style="color: #004993;">x</span> = <span style="color: #000000;">&#40;</span>bmFullsize.<span style="color: #004993;">width</span> <span style="color: #000000; font-weight: bold;">+</span> bmHalfsize.<span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span>;
	bmThumbsize.<span style="color: #004993;">smoothing</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
	showImages<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> showImages<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>bmFullsize<span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>bmHalfsize<span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>bmThumbsize<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>


]]></content:encoded>
			<wfw:commentRss>http://ryanbosinger.com/blog/2008/resizing-bitmap-images-with-actionscript-30/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>APE Class Model</title>
		<link>http://ryanbosinger.com/blog/2008/ape-class-model/</link>
		<comments>http://ryanbosinger.com/blog/2008/ape-class-model/#comments</comments>
		<pubDate>Thu, 29 May 2008 16:30:42 +0000</pubDate>
		<dc:creator>rbosinger</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://ryanbosinger.com/blog/?p=10</guid>
		<description><![CDATA[Click above for a giant layout of all the APE classes and the way they inherit each other. Definitely helpful.]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://ryanbosinger.com/blog/wp-content/uploads/2008/05/ape-0_4-class-model.png"><img class="size-medium wp-image-11" title="Ape Class Model" src="http://ryanbosinger.com/blog/wp-content/uploads/2008/05/ape-0_4-class-model-300x175.png" alt="" width="300" height="175" /></a></p>
<p>
Click above for a giant layout of all the APE classes and the way they inherit each other.  Definitely helpful.
</p>]]></content:encoded>
			<wfw:commentRss>http://ryanbosinger.com/blog/2008/ape-class-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
