<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>Tiago&#039;s Weblog &#187; as3</title>
	<atom:link href="http://blog.six4rty.ch/tag/as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.six4rty.ch</link>
	<description>Code &#38; Technology Aficionado - Come for the Flash, stay for more!</description>
	<lastBuildDate>Sat, 24 Jul 2010 16:52:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
		<item>
		<title>AS3: Drawing dynamic anchor lines</title>
		<link>http://blog.six4rty.ch/2010/07/13/as3-drawing-dynamic-anchor-lines/</link>
		<comments>http://blog.six4rty.ch/2010/07/13/as3-drawing-dynamic-anchor-lines/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 18:14:12 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Quick Hints]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[Drawing]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=732</guid>
		<description><![CDATA[Based on this post on the Adobe&#8217;s AS3 forum, I thought  I would create a simple class that takes care of the requested task. The whole idea is basically to draw a line dynamically between 2 displayobjects, on top of it when one object is being dragged the line is redrawn along based on the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.six4rty.ch/wp-content/uploads/2010/07/as3code.jpg"><img class="size-medium wp-image-724 alignleft" style="margin: 10px;" title="as3code" src="http://blog.six4rty.ch/wp-content/uploads/2010/07/as3code-300x270.jpg" alt="" width="210" height="189" /></a>Based on <a href="http://forums.adobe.com/thread/669998?tstart=0" target="_blank">this</a> post on the Adobe&#8217;s AS3 forum, I thought  I would create a simple class that takes care of the requested task.</p>
<p>The whole idea is basically to draw a line dynamically between 2 displayobjects, on top of it when one object is being dragged the line is redrawn along based on the second sprite position.</p>
<p>There is  a lot more that can be done, like avoiding other sprites, drawing multiple lines attached to multiple buttons and so on. but I think this class can give you a good head start for future implementations.</p>
<p>First of all there are a few things that we need to consider before starting, let&#8217;s take a look at the first few tasks</p>
<p>1. Every Sprite needs to know to which button it has been linked to. You need to store this somewhere.<br />
2. Every Sprite needs a specific anchor point that is used as endpoint of the drawn line.<br />
3. As soon the drag method is started we need to know where  the one end of the line (from the sprite that is not being dragged by the mouse) is positioned at. This is something that we really need to do once on a startDrag method.</p>
<p>Here&#8217;s what I&#8217;ve done:<span id="more-732"></span><br />
Based on the notices above, I&#8217;ve created a new Class called ConnectedSprite a simple class which extends the Sprite Class but with a few more options that helps us towards our goal and this is how our class looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">DisplayObject</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Point</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ConnectedSprite <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _anchorPoint			:Point;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _relativeObject		:ConnectedSprite;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ConnectedSprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> anchorPoint <span style="color: #66cc66;">&#40;</span> p:Point <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_anchorPoint = p;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> anchorPoint<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:Point
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _anchorPoint;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> relativeObject <span style="color: #66cc66;">&#40;</span> co:ConnectedSprite <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_relativeObject = co;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> relativeObject<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:ConnectedSprite
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _relativeObject;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Just to give you quick overview of what we are doing here:<br />
Basically we are extending the Sprite class and adding two new variables _<strong>anchorPoint</strong> and _<strong>relativeObject</strong>, those are accessible by using getters &amp; setters.<br />
The _anchorpoint variable holds a fixed x and y position where our line should connect to and the _relativeObject has a reference to the other sprite which is being conntected to.<br />
Pretty simple but effective.</p>
<p>That was already it, we now just need to create two new ConnectedSprite instances pass the needed values and there you go, below the BaseClass I&#8217;ve built for this example:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AnchoredSprite <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _spriteA			:ConnectedSprite;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _spriteB			:ConnectedSprite;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _movingTarget		:ConnectedSprite;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _staticTargetPos		:Point		= <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _connector			:Sprite;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AnchoredSprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			_connector = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span> _connector <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_spriteA = <span style="color: #000000; font-weight: bold;">new</span> ConnectedSprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_spriteA.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span> 0xff0000, <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span>;
			_spriteA.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">50</span> <span style="color: #66cc66;">&#41;</span>;
			_spriteA.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_spriteA.<span style="color: #006600;">anchorPoint</span> = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span> _spriteA.<span style="color: #0066CC;">width</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>, _spriteA.<span style="color: #0066CC;">height</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span> _spriteA <span style="color: #66cc66;">&#41;</span>;
			_spriteA.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, mouseDownHandler <span style="color: #66cc66;">&#41;</span>;
			_spriteA.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, mouseUpHandler <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_spriteB = <span style="color: #000000; font-weight: bold;">new</span> ConnectedSprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_spriteB.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span> 0x0000ff, <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span>;
			_spriteB.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">50</span> <span style="color: #66cc66;">&#41;</span>;
			_spriteB.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_spriteB.<span style="color: #006600;">anchorPoint</span> = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span> _spriteB.<span style="color: #0066CC;">width</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>, _spriteB.<span style="color: #0066CC;">height</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span> _spriteB <span style="color: #66cc66;">&#41;</span>;
			_spriteB.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, mouseDownHandler <span style="color: #66cc66;">&#41;</span>;
			_spriteB.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, mouseUpHandler <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_spriteA.<span style="color: #006600;">relativeObject</span> = _spriteB;
			_spriteB.<span style="color: #006600;">relativeObject</span> = _spriteA;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> mouseDownHandler<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>:MouseEvent <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">startDrag</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">false</span> <span style="color: #66cc66;">&#41;</span>;
			_movingTarget = <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span> as ConnectedSprite;
			_staticTargetPos.<span style="color: #006600;">x</span> = _movingTarget.<span style="color: #006600;">relativeObject</span>.<span style="color: #006600;">x</span> + _movingTarget.<span style="color: #006600;">relativeObject</span>.<span style="color: #006600;">anchorPoint</span>.<span style="color: #006600;">x</span>;
			_staticTargetPos.<span style="color: #006600;">y</span> = _movingTarget.<span style="color: #006600;">relativeObject</span>.<span style="color: #006600;">y</span> + _movingTarget.<span style="color: #006600;">relativeObject</span>.<span style="color: #006600;">anchorPoint</span>.<span style="color: #006600;">y</span>;
			addEventListener<span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, drawLine <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> mouseUpHandler<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>:MouseEvent <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">stopDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_movingTarget = <span style="color: #000000; font-weight: bold;">null</span>;
&nbsp;
			removeEventListener<span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, drawLine <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> drawLine<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>:MouseEvent <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_connector.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_connector.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">1</span>, 0x333333 <span style="color: #66cc66;">&#41;</span>;
			_connector.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span> _staticTargetPos.<span style="color: #006600;">x</span>, _staticTargetPos.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&#41;</span>;
			_connector.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span> _movingTarget.<span style="color: #006600;">x</span> + _movingTarget.<span style="color: #006600;">anchorPoint</span>.<span style="color: #006600;">x</span>, _movingTarget.<span style="color: #006600;">y</span> + _movingTarget.<span style="color: #006600;">anchorPoint</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">updateAfterEvent</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>it&#8217;s quite a long base class for this simple task, it could have been reduced using other drawing methods, but that is something that I leave up to you.</p>
<p>Below a working example and you can download the source files here: <a href="http://blog.six4rty.ch/wp-content/uploads/2010/07/ConnectedSprite.zip">ConnectedSprite</a></p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="400" height="300">
      <param name="movie" value="http://blog.six4rty.ch/wp-content/uploads/2010/07/AnchoredSprite1.swf" />
      <param name="allowfullscreen" value="true" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://blog.six4rty.ch/wp-content/uploads/2010/07/AnchoredSprite1.swf" width="400" height="300" allowfullscreen="true">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2010/07/13/as3-drawing-dynamic-anchor-lines/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
		<item>
		<title>SWFObject &amp; SWFAddress &#8211; compatibility</title>
		<link>http://blog.six4rty.ch/2010/07/09/swfobject-swfaddress-compatibility/</link>
		<comments>http://blog.six4rty.ch/2010/07/09/swfobject-swfaddress-compatibility/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 12:40:37 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[SWFAddress]]></category>
		<category><![CDATA[SWFObject]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=708</guid>
		<description><![CDATA[Who doesn&#8217;t know SWFObject &#38; SWFAddress? These two JavaScript buddies are the best a serious Flash Developer can have. SWFObject embeds your Flash nicely and browser independent, it has gone a long way and now it&#8217;s even the default publishing method in Flash Builder and Flash Catalyst (not sure about Flash CS5 ), you can [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.six4rty.ch/wp-content/uploads/2010/07/swfObjaddImg.jpg"><img class="alignnone size-medium wp-image-709" title="swfObjaddImg" src="http://blog.six4rty.ch/wp-content/uploads/2010/07/swfObjaddImg-300x90.jpg" alt="" width="300" height="90" /></a></p>
<p>Who doesn&#8217;t know SWFObject &amp; SWFAddress? These two JavaScript buddies are the best a serious Flash Developer can have.</p>
<p><a href="http://code.google.com/p/swfobject/" target="_blank">SWFObject </a>embeds your Flash nicely and browser independent, it has gone a long way and now it&#8217;s even the default publishing method in Flash Builder and Flash Catalyst (not sure about Flash CS5 ), you can read a more detailed history on the <a href="http://code.google.com/p/swfobject/wiki/history" target="_blank">projects history site</a>.</p>
<p><a href="http://www.asual.com/swfaddress/" target="_blank">SWFAddress </a>is a small library that provides deep-linking functionality in your Flash projects, it enables you to create unique virtual URL&#8217;s which enables Search Engines to index your flash content and of course the utilisation of the browsers back and forward buttons eg. history capabilities.<br />
<span id="more-708"></span></p>
<p>Usually in our development process we integrate these 2 buddies right at the beginning of the project, before we even code any AS3 line, these two are already in the html template inside FlashBuilder. Last time I started a new project I downloaded the latest versions (at that time) from these libraries and implemented them. Everything was working fine, and it works fine, but sadly only on FF3+ and IE8.. what happened to the strength of SWFObject?</p>
<p>After scrolling through a few posts and forums I decided to gradually downgrade every version of each Library backwards to see what happens. I must mention that the default embedding and display of flash content works perfectly, but when you need to send flashvars or parameters to your swf, there&#8217;s when things break.</p>
<p><strong>Solution?</strong><br />
It&#8217;s an easy one, but painful to find out as it took me a few hours to get it to work.<br />
SWFObject and SWFAddress are in deed buddies, but they need to be coordinated  properly.</p>
<p><strong>First pitfall:</strong><br />
The order that the javascript is being placed is very important, you <strong>NEED </strong>to place it in the order:<br />
1. SWFObject 2. SWFAddress all other Javascripts you might have in place shouldn&#8217;t bother these two, but it&#8217;s always safer to put your custom stuff after the SWFAddress import.</p>
<p><strong>Second pitfall:</strong><br />
There are various versions of each library some work together some don&#8217;t. I didn&#8217;t had the time to create a nice working table, but I promise you that I&#8217;m going to post one in the near future, but I can tell you what definately works 100%, SWFObject 2.2 &amp; SWFAddress 2.2, yes both libraries with the same version number.</p>
<p><strong>Third pitfall:</strong><br />
Sometimes ( I can&#8217;t tell you in which formation ) flashvars as parameters don&#8217;t get through to the SWF, the only workaround I found was to instead of using a parameters array I&#8217;ve passed an arguments array, that fixed all the troubles.</p>
<p>I know it&#8217; s weird and I would like to elaborate more on this, but currently I just don&#8217;t have the time to do it, but don&#8217;t be afraid I will get a list up soon with my testing results.<br />
If you have any questions to this topic, drop me a line and I will try to help you out.</p>
<p><strong>UPDATE:</strong><br />
Changed version numbers from 2.3 to 2.2, thanks to Ven</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2010/07/09/swfobject-swfaddress-compatibility/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
		<item>
		<title>Zinc &#8211; Saving images</title>
		<link>http://blog.six4rty.ch/2009/12/02/zinc-saving-images/</link>
		<comments>http://blog.six4rty.ch/2009/12/02/zinc-saving-images/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 19:48:00 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[Zinc]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=616</guid>
		<description><![CDATA[It was obvious that I had to write a few more lines about Zinc in the near future, but somehow this topic didn&#8217;t leave me alone at all, and no, I&#8217;m not writing about Zinc because I like it, I&#8217;m writing this because I don&#8217;t want that other people fall into the traps I fell [...]]]></description>
			<content:encoded><![CDATA[<p>It was obvious that I had to write a few more lines about Zinc in the near future, but somehow this topic didn&#8217;t leave me alone at all, and no, I&#8217;m not writing about Zinc because I like it, I&#8217;m writing this because I don&#8217;t want that other people fall into the traps I fell while using it. Do I like Zinc? Yes &amp; No, it&#8217;s a very weird situation, it&#8217;s useful, it would be even more useful if they would do their job right, but <a href="http://blog.six4rty.ch/2009/11/29/zinc-a-love-hate-relationship/" target="_blank">I already wrote about it here</a>. So let&#8217;s leave this discussion out of here.</p>
<p>So let&#8217;s begin from the ground up, your goal is to resize and save the newly resized files back again into a jpeg. Sounds easy?<br />
It should be but it isn&#8217;t!!</p>
<p>First of all I have to tell you that I began my project with Zinc 3.0 which supports bytearrays, it was really cool to work with it, as I was able to use the JPEGEncoder class that anyway writes bytearrays.</p>
<p><span id="more-616"></span></p>
<p>Let&#8217;s look at the methods available:<br />
<em>setData();<br />
writeData();<br />
</em><em>setDataBA();<br />
writeDataBA();</em></p>
<p>You would achieve our goal somehow like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> bmp:Bitmap = DisplayToBitmap.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>bSprite, <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> bmd:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>bmp.<span style="color: #0066CC;">width</span>, bmp.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;
bmd.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>bmp<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> jpgEnc:JPGEncoder = <span style="color: #000000; font-weight: bold;">new</span> JPGEncoder<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">85</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> jpgStream:ByteArray = jpgEnc.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span>bmd<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> jpgPath:<span style="color: #0066CC;">String</span> = persFolder + <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>My Pictures<span style="color: #000099; font-weight: bold;">\\</span>myScreensaverThumbs<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span> + _arrayCCopy<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
&nbsp;
_convertedArray.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>jpgPath<span style="color: #66cc66;">&#41;</span>;
&nbsp;
mdm.<span style="color: #006600;">FileSystem</span>.<span style="color: #006600;">BinaryFile</span>.<span style="color: #006600;">setDataBA</span><span style="color: #66cc66;">&#40;</span>jpgStream<span style="color: #66cc66;">&#41;</span>;
mdm.<span style="color: #006600;">FileSystem</span>.<span style="color: #006600;">BinaryFile</span>.<span style="color: #006600;">writeDataBA</span><span style="color: #66cc66;">&#40;</span>jpgPath<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>But since I had to use Zinc 2.5 because of performance problems with the application, guess what? You don&#8217;t have the possibility to write a bytearray down to the harrdisk with the <em>writeDataBA()</em> method. So how the heck are you going to write a jpeg?</p>
<p>Let&#8217;s look at the methods available:<br />
<em>setData();<br />
writeData();</em></p>
<p>Yeh, it&#8217;s not much, and yeh it didn&#8217;t change a lot in Zinc 3.0 besides that you can write Bytearrays.<br />
So what you have to do is basicall write HEX code or Pipe ( | ) delimited strings, do that on a few dozen images and you can go get a cup of coffee and when you back it might be done by then.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> bmp:Bitmap = DisplayToBitmap.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>sp, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> pngBA:ByteArray = PNGEncoder.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span>bmp.<span style="color: #006600;">bitmapData</span><span style="color: #66cc66;">&#41;</span>;
MonsterDebugger.<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, pngBA<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> dataString:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:uint=<span style="color: #cc66cc;">0</span>; i <span style="color: #66cc66;">&amp;</span>lt; pngBA.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&amp;</span>gt;<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
	dataString += <span style="color: #ff0000;">&quot;|&quot;</span>;
    <span style="color: #66cc66;">&#125;</span>
    dataString += pngBA<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
<span style="color: #66cc66;">&#125;</span>
mdm.<span style="color: #006600;">FileSystem</span>.<span style="color: #006600;">BinaryFile</span>.<span style="color: #006600;">setData</span><span style="color: #66cc66;">&#40;</span>dataString<span style="color: #66cc66;">&#41;</span>;
mdm.<span style="color: #006600;">FileSystem</span>.<span style="color: #006600;">BinaryFile</span>.<span style="color: #006600;">writeData</span><span style="color: #66cc66;">&#40;</span>persFolder + <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>My Pictures<span style="color: #000099; font-weight: bold;">\\</span>myScreensaverThumbs<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span> + _arrayCCopy<span style="color: #66cc66;">&#91;</span>v<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Now that you know how to to handle this, let&#8217;s think about  a few methods that Zinc 2.5 API provides you with:</p>
<p><em>bmpToJpg();</em><br />
Nice little function but it only works if you have .bmp&#8217;s on your harddrive, who uses .bmp&#8217;s nowadays?</p>
<p><em>jpgToBmp();</em><br />
hmm.. sounds better, you can grab a jpeg and convert it to a .bmp file, after that you can use the <em>bmpToJpg()</em> method to save them back, but come on, does that really make sense? After all you are using 2 methods to do a simple conversion and resave.</p>
<p><em>deleteFile();</em><br />
Believe me or not, actually it&#8217;s quite obvious, you converted a jpeg to bmp and the bmp to jpeg, now you have<br />
1) an original file<br />
2) a bitmap file<br />
3) a converted file<br />
Isn&#8217;t that one too much?<br />
Yep, now you have to use the <em>deletefile() </em>method to delete the bmp file which you are definately not going to use.</p>
<p>Now you used 3 methods to accomplish a simple task, that can be done in pure as3 with less lines of code. Now you ask yourself  &#8220;Tiago you are talking about Zinc 2.5, that&#8217;s anyway outdated&#8221; have a look at the <a href="http://www.multidmedia.com/support/livedocs/" target="_blank">methods available for Zinc 3.0</a>. As you see they don&#8217;t have a simple &#8220;read jpeg / save jpeg&#8221; method. WHY NOT?????</p>
<p>But let&#8217;s continue, by now you know how to resize and resave images with Zinc 2.5 and Zinc 3.0, but you are probably not only going to convert one single image on the fly, that would be kind of boring no?</p>
<p>Let&#8217;s try to get a list of files from a specific directory, to accomplish that we need the <em>getFileList()</em> method, below a simple line on how to use it</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> myFiles:<span style="color: #0066CC;">Array</span> = mdm.<span style="color: #006600;">FileSystem</span>.<span style="color: #006600;">getFileList</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;c:<span style="color: #000099; font-weight: bold;">\\</span>my images<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span>, <span style="color: #ff0000;">&quot;*.jpg&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Sounds simple, you build an array and call the getFileList method pointing to the location you wish and filtering it based on the file ending, at the end you don&#8217;t want to get some weird errors because you try to convert a .doc or whatsoever into a .bmp / .jpg</p>
<p>if you don&#8217;t believe me, then try this out on your own doesn&#8217;t matter which version of Zinc you own</p>
<ol>
<li>Create a folder on your c drive (it&#8217;s easier to target then anything else)</li>
<li>Drop a few images and rename the filetype of some of the files to .JPEG, .jpg, .jpeg (case sensitive)</li>
<li>Run the code above in your project using the path to the folder you just created</li>
</ol>
<p><strong>Result:</strong><br />
Only the files with the case sensitive .jpg will be pushed into the array, yeh now you know it, this damn thing is case sensitive, so let&#8217;s create some more arrays to handle the different filetypes and use some more processing time and memory then needed, the same goes for every filetype you want to push in. In my case I had to get all images with a filetype of (.jpg, .jpeg, .JPG, .JPEG, .bmp, .BMP, .png, .PNG) 8 querys on the filesystem all using the same method, sigh..</p>
<p>Have you ever ran into a Zinc problem before, let us hear your experience with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2009/12/02/zinc-saving-images/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
		<item>
		<title>AS3 &#8211; textfield setSelection()</title>
		<link>http://blog.six4rty.ch/2009/08/24/as3-textfield-setselection/</link>
		<comments>http://blog.six4rty.ch/2009/08/24/as3-textfield-setselection/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 13:25:49 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[as3]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=592</guid>
		<description><![CDATA[Have you tried to set selection on atextfield after a validation procedure? Have you noticed that it doesn&#8217;t work quite right? Here&#8217;s the quick solution for that: Normally you would use the yourTextField.setSelection(startIndex, endIndex); method, but like I said before that doesn&#8217;t really work very well. You just need to set the focus to the [...]]]></description>
			<content:encoded><![CDATA[<p>Have you tried to set selection on atextfield after a validation procedure? Have you noticed that it doesn&#8217;t work quite right? Here&#8217;s the quick solution for that:</p>
<p>Normally you would use the yourTextField.setSelection(startIndex, endIndex); method, but like I said before that doesn&#8217;t really work very well.</p>
<p>You just need to set the focus to the textfield and then set the selection:</p>
<p>Example: (assuming you have a textfield called &#8220;tf&#8221;)</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">....
<span style="color: #006600;">tf</span>.<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">focus</span> = tf;
tf.<span style="color: #0066CC;">setSelection</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, tf.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span>;
...</pre></div></div>

<p>And that&#8217;s how you solve the textfield.setSelection() problem</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2009/08/24/as3-textfield-setselection/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
	</channel>
</rss>
