<?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>as3 blog</title>
	<atom:link href="http://www.ninjabonsai.net/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.ninjabonsai.net/blog</link>
	<description>thoughts on actionscript 3 development</description>
	<lastBuildDate>Thu, 29 Mar 2012 03:34:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>search and replace in strings</title>
		<link>http://www.ninjabonsai.net/blog/?p=104</link>
		<comments>http://www.ninjabonsai.net/blog/?p=104#comments</comments>
		<pubDate>Mon, 26 Mar 2012 05:46:01 +0000</pubDate>
		<dc:creator>shunryu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ninjabonsai.net/blog/?p=104</guid>
		<description><![CDATA[it&#8217;s been a while since i needed to do this. nice technique is to use &#8216;split&#8217; to break the string into an array using the split&#8217;s arguments as the deliminator then &#8216;join&#8217; to stick is back together using joins arg to put between each element. the effect is a search and replace var str:String = [...]]]></description>
			<content:encoded><![CDATA[<p>it&#8217;s been a while since i needed to do this. nice technique is to use &#8216;split&#8217; to break the string into an array using the split&#8217;s arguments as the deliminator then &#8216;join&#8217; to stick is back together using joins arg to put between each element. the effect is a search and replace</p>
<p><p>
								<pre class="Plum_Code_Box"><code class="javascript">var str:String = &quot;this is a string with some spaces that need replacing with _&quot;
str = str.split(&quot; &quot;).join(&quot;_&quot;);
// simple :)</code>
									</pre>
							</p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjabonsai.net/blog/?feed=rss2&#038;p=104</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recursively delete .svn directories</title>
		<link>http://www.ninjabonsai.net/blog/?p=101</link>
		<comments>http://www.ninjabonsai.net/blog/?p=101#comments</comments>
		<pubDate>Sun, 11 Mar 2012 23:51:29 +0000</pubDate>
		<dc:creator>shunryu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ninjabonsai.net/blog/?p=101</guid>
		<description><![CDATA[if you&#8217;ve ever needed to delete all the hidden .svn directories from a project running a script like this in terminal is very helpful (will work in OSX and Linux) cd to the root directory then run the following&#8230; rm -rf `find . -type d -name .svn` make sure to use the ` character. all [...]]]></description>
			<content:encoded><![CDATA[<p>if you&#8217;ve ever needed to delete all the hidden .svn directories from a project running a script like this in terminal is very helpful (will work in OSX and Linux)</p>
<p>cd to the root directory then run the following&#8230;</p>
<p>rm -rf `find . -type d -name .svn`</p>
<p>make sure to use the ` character. all .svn directories are now gone</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjabonsai.net/blog/?feed=rss2&#038;p=101</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>embeding json, xml and text files</title>
		<link>http://www.ninjabonsai.net/blog/?p=93</link>
		<comments>http://www.ninjabonsai.net/blog/?p=93#comments</comments>
		<pubDate>Wed, 02 Nov 2011 18:49:30 +0000</pubDate>
		<dc:creator>shunryu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ninjabonsai.net/blog/?p=93</guid>
		<description><![CDATA[you could load some json data at runtime and most of the time this is the best thing to do as it&#8217;s likely you&#8217;ll want to be able to change that data without recompiling. but what about some json data for a sprite sheet? it&#8217;s easy enough to embed images in actionscript but what about [...]]]></description>
			<content:encoded><![CDATA[<p>you could load some json data at runtime and most of the time this is the best thing to do as it&#8217;s likely you&#8217;ll want to be able to change that data without recompiling. but what about some json data for a sprite sheet? it&#8217;s easy enough to embed images in actionscript but what about text files? it&#8217;s a little bit different..</p>
<p><p>
								<pre class="Plum_Code_Box"><code class="java">package
{
  public class EmbedJsonTest extends Sprite
  {
    [Embed(source=&quot;data.json&quot;,mimeType=&quot;application/octet-stream&quot;)]
    private const JsonData : Class;

    public function EmbedJsonTest()
    {
      var ba : ByteArray = new JsonData() as ByteArray;

      trace(&quot;JsonData = &quot; + ba.readUTFBytes(ba.length));
    }
  }
}</code>
									</pre>
							</p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjabonsai.net/blog/?feed=rss2&#038;p=93</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>file path of swf file</title>
		<link>http://www.ninjabonsai.net/blog/?p=88</link>
		<comments>http://www.ninjabonsai.net/blog/?p=88#comments</comments>
		<pubDate>Mon, 24 Oct 2011 13:45:42 +0000</pubDate>
		<dc:creator>shunryu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ninjabonsai.net/blog/?p=88</guid>
		<description><![CDATA[here&#8217;s something simple but useful.. getting the file path of your swf file at runtime var filePath : String = this.loaderInfo.url; var lastIndex : int = filePath.lastIndexOf(&#34;/&#34;); trace(filePath.substr(0, lastIndex + 1)); but this will only work once the DisplayObject is added to the stage so you can&#8217;t put it in the constructor. you need to [...]]]></description>
			<content:encoded><![CDATA[<p>here&#8217;s something simple but useful.. getting the file path of your swf file at runtime</p>
<p><p>
								<pre class="Plum_Code_Box"><code class="java">var filePath : String = this.loaderInfo.url;
var lastIndex : int = filePath.lastIndexOf(&quot;/&quot;);
trace(filePath.substr(0, lastIndex + 1));</code>
									</pre>
							</p></p>
<p>but this will only work once the DisplayObject is added to the stage so you can&#8217;t put it in the constructor. you need to add an ADDED_TO_STAGE event listener then run it inside an init function.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjabonsai.net/blog/?feed=rss2&#038;p=88</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>turn camera off</title>
		<link>http://www.ninjabonsai.net/blog/?p=80</link>
		<comments>http://www.ninjabonsai.net/blog/?p=80#comments</comments>
		<pubDate>Wed, 19 Oct 2011 09:39:43 +0000</pubDate>
		<dc:creator>shunryu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ninjabonsai.net/blog/?p=80</guid>
		<description><![CDATA[turning on the users web cam and displaying it is easy enough.. var camera : Camera = Camera.getCamera(); camera.setQuality(0, 90); camera.setMode(720, 576, 25); if (camera != null) { video = new Video(720, 576); video.attachCamera(camera); addChild(video); } else { trace(&#34;go buy a camera&#34;); } but if the user navigates to another part of your app and [...]]]></description>
			<content:encoded><![CDATA[<p>turning on the users web cam and displaying it is easy enough..</p>
<p><p>
								<pre class="Plum_Code_Box"><code class="java">var camera : Camera = Camera.getCamera();
camera.setQuality(0, 90);
camera.setMode(720, 576, 25);

if (camera != null)
{
  video = new Video(720, 576);
  video.attachCamera(camera);
  addChild(video);
}
else
{
  trace(&quot;go buy a camera&quot;);
}</code>
									</pre>
							</p></p>
<p>but if the user navigates to another part of your app and you don&#8217;t remove the camera object it will continue to run and use a whole lot of cpu. removing it&#8217;s pretty easy too but also easy to forget..</p>
<p><p>
								<pre class="Plum_Code_Box"><code class="java">video.attachCamera(null);
video.clear();
removeChild(_video);

camera = null;</code>
									</pre>
							</p></p>
<p>the key part there is <em>video.attachCamera(null);</em> that&#8217;s the part that will turn off the little light next to your notebook&#8217;s camera <img src='http://www.ninjabonsai.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjabonsai.net/blog/?feed=rss2&#038;p=80</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tracing Objects</title>
		<link>http://www.ninjabonsai.net/blog/?p=71</link>
		<comments>http://www.ninjabonsai.net/blog/?p=71#comments</comments>
		<pubDate>Fri, 14 Oct 2011 11:02:53 +0000</pubDate>
		<dc:creator>shunryu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ninjabonsai.net/blog/?p=71</guid>
		<description><![CDATA[simplest way to do this is to convert the object to a JSON string and trace that out.. var obj : Object = {uid:15, title:&#34;hello&#34;}; var jsonObj : String = JSON.encode(obj); trace(jsonObj); the JSON class here is part of a useful library of as3 utility class files from mike chambers available here.. https://github.com/mikechambers/as3corelib another very [...]]]></description>
			<content:encoded><![CDATA[<p>simplest way to do this is to convert the object to a JSON string and trace that out..</p>
<p><p>
								<pre class="Plum_Code_Box"><code class="java">var obj : Object = {uid:15, title:&quot;hello&quot;};
var jsonObj : String = JSON.encode(obj);
trace(jsonObj);</code>
									</pre>
							</p></p>
<p>the JSON class here is part of a useful library of as3 utility class files from mike chambers available here..</p>
<p><a href="https://github.com/mikechambers/as3corelib" target="_blank">https://github.com/mikechambers/as3corelib</a></p>
<p>another very useful one that&#8217;s part of this collection is a JPG encoder that takes a BitmapData object and returns a ByteArray that can then be sent to a server with AMF.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjabonsai.net/blog/?feed=rss2&#038;p=71</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CacheAsBitmapMatrix on Mobile Devices</title>
		<link>http://www.ninjabonsai.net/blog/?p=66</link>
		<comments>http://www.ninjabonsai.net/blog/?p=66#comments</comments>
		<pubDate>Thu, 22 Sep 2011 09:17:05 +0000</pubDate>
		<dc:creator>shunryu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ninjabonsai.net/blog/?p=66</guid>
		<description><![CDATA[cacheAsBitmap is a property that&#8217;s a good idea to set to true for display objects that will be moved around containing vector content. flashPlayer has to redraw vectors that are transformed and this hurts performance. by setting cacheAsBitmap to true you&#8217;re effectively converting the vector to a bitmap which flashPlayer can move round alot easier. [...]]]></description>
			<content:encoded><![CDATA[<p>cacheAsBitmap is a property that&#8217;s a good idea to set to true for display objects that will be moved around containing vector content. flashPlayer has to redraw vectors that are transformed and this hurts performance. by setting cacheAsBitmap to true you&#8217;re effectively converting the vector to a bitmap which flashPlayer can move round alot easier. this will work great if all you&#8217;re doing is moving it on the x and y but if you want to scale, rotate or change the alpha, cacheAsBitmap will make performace worse as it will have to redraw the vector, apply the transformation and cache it as a bitmap all over again. there is a nice extra available at the moment only for Air on mobile devices called cacheAsBitmapMatrix. this setting will allow scale, rotation and alpha transformations without flash player needing to redraw the vector..</p>
<p><p>
								<pre class="Plum_Code_Box"><code class="javascript">var box : Sprite = new Sprite();
box.graphics.beginFill(0x009900);
box.graphics.drawRect(0, 0, 50, 50);
box.graphics.endFill();
addChild(box);

box.cacheAsBitmapMatrix = box.transform.concatenatedMatrix;
box.cacheAsBitmap = true;

// now move, scale, rotate and change the alpha of box much more efficiently on mobile devices</code>
									</pre>
							</p></p>
<p>note: cacheAsBitmap and cacheAsBitmapMatrix are only for displayObjects that do not have nested animation. this will require flash player to redraw on each frame the contents on the displayObject that changed</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjabonsai.net/blog/?feed=rss2&#038;p=66</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blitting</title>
		<link>http://www.ninjabonsai.net/blog/?p=63</link>
		<comments>http://www.ninjabonsai.net/blog/?p=63#comments</comments>
		<pubDate>Thu, 15 Sep 2011 07:18:55 +0000</pubDate>
		<dc:creator>shunryu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ninjabonsai.net/blog/?p=63</guid>
		<description><![CDATA[i&#8217;m just writing this one little thing here about blitting in as3 so i never forget it.. var bmd : BitmapData; // some other code here bmd.lock(); for(var i : uint = 0; i &#60; 20; i++) { // multiple calls to bmd.copyPixels } bmd.unlock(); // bit faster that&#8217;s the most important thing to know. [...]]]></description>
			<content:encoded><![CDATA[<p>i&#8217;m just writing this one little thing here about blitting in as3 so i never forget it..</p>
<p><p>
								<pre class="Plum_Code_Box"><code class="javascript">var bmd : BitmapData;
// some other code here

 bmd.lock();

for(var i : uint = 0; i &lt; 20; i++)
{
    // multiple calls to bmd.copyPixels
}

 bmd.unlock();

// bit faster</code>
									</pre>
							</p></p>
<p>that&#8217;s the most important thing to know. before doing this i was wondering why the performance using blitting wasn&#8217;t any better than standard rendering.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjabonsai.net/blog/?feed=rss2&#038;p=63</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BitmapData smoothing</title>
		<link>http://www.ninjabonsai.net/blog/?p=57</link>
		<comments>http://www.ninjabonsai.net/blog/?p=57#comments</comments>
		<pubDate>Mon, 12 Sep 2011 08:40:19 +0000</pubDate>
		<dc:creator>shunryu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ninjabonsai.net/blog/?p=57</guid>
		<description><![CDATA[Turning on smoothing for Bitmap objects in as3 is easy enough.. // Bitmap(BitmapData, pixelsnapping, smoothing) var bm : Bitmap = new Bitmap(bmd, &#34;auto&#34;, true); but what confused me is if i then draw something to the BitmapData property, smoothing gets set to false. bm.bitmapData.draw(someDisplayObj); // now smoothing for the Bitmap is set back to the [...]]]></description>
			<content:encoded><![CDATA[<p>Turning on smoothing for Bitmap objects in as3 is easy enough..</p>
<p><p>
								<pre class="Plum_Code_Box"><code class="javascript">// Bitmap(BitmapData, pixelsnapping, smoothing)
var bm : Bitmap = new Bitmap(bmd, &quot;auto&quot;, true);</code>
									</pre>
							</p></p>
<p>but what confused me is if i then draw something to the BitmapData property, smoothing gets set to false.</p>
<p><p>
								<pre class="Plum_Code_Box"><code class="javascript">bm.bitmapData.draw(someDisplayObj);
// now smoothing for the Bitmap is set back to the default false. so..

bm.smoothing = true;</code>
									</pre>
							</p></p>
<p>easy enough to fix</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjabonsai.net/blog/?feed=rss2&#038;p=57</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FDT, ANT and FTP</title>
		<link>http://www.ninjabonsai.net/blog/?p=37</link>
		<comments>http://www.ninjabonsai.net/blog/?p=37#comments</comments>
		<pubDate>Fri, 12 Aug 2011 12:52:55 +0000</pubDate>
		<dc:creator>shunryu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ninjabonsai.net/blog/?p=37</guid>
		<description><![CDATA[if you&#8217;ve used ANT inside of FDT you might have like me thought.. can i use it to FTP my .swf to a server after compiling? answer is yes but you need to get some .jar files. i followed a nice tutorial on doing this here http://www.funky-monkey.nl/blog/2010/09/29/using-ftp-with-ant-and-fdt/ that worked well but the server i&#8217;m working [...]]]></description>
			<content:encoded><![CDATA[<p>if you&#8217;ve used ANT inside of FDT you might have like me thought.. can i use it to FTP my .swf to a server after compiling? answer is yes but you need to get some .jar files. i followed a nice tutorial on doing this here</p>
<p><a href="http://www.funky-monkey.nl/blog/2010/09/29/using-ftp-with-ant-and-fdt/">http://www.funky-monkey.nl/blog/2010/09/29/using-ftp-with-ant-and-fdt/</a></p>
<p>that worked well but the server i&#8217;m working with at the moment is SFTP (SSH File Transfer Protocol) and it didn&#8217;t work. so after a bit more searching around i found how it&#8217;s done. before reading on go over the content at the link above then download <a title="jsch-0.1.44.jar" href="http://sourceforge.net/projects/jsch/files/jsch.jar/0.1.44/jsch-0.1.44.jar/download">this .jar</a> file and copy it to..<br />
<br />FDT/plugins/org.apache.ant_1.7.1v20100518-1145/lib/<br />
<br />
and add it to the Ant Home Entries Classpath as described in the above tutorial</p>
<p>then instead of using the FTP tag in ANT use SCP like this..</p>
<p><p>
								<pre class="Plum_Code_Box"><code class="html">&lt;scp remoteTodir=&quot;username@yourwebsite.com:/home/username/public_html&quot; password=&quot;pword&quot; trust=&quot;yes&quot; sftp=&quot;true&quot; port=&quot;22&quot;&gt;
  &lt;fileset dir=&quot;../bin&quot;&gt;
    &lt;include name=&quot;main.swf&quot; /&gt;
    &lt;include name=&quot;index.html /&gt;
  &lt;/fileset&gt;
&lt;/scp&gt;</code>
									</pre>
							</p></p>
<p>info on SCP can be found here..</p>
<p><a href="http://ant.apache.org/manual/Tasks/scp.html">http://ant.apache.org/manual/Tasks/scp.html</a></p>
<p>hope this helps</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjabonsai.net/blog/?feed=rss2&#038;p=37</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

