<?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>mandarin.no &#187; flex</title>
	<atom:link href="http://mandarin.no/tag/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://mandarin.no</link>
	<description></description>
	<lastBuildDate>Tue, 17 Aug 2010 09:35:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>AS3 Snippet #3: Remove all childs</title>
		<link>http://mandarin.no/as3/as3-snippet-3-remove-all-childs/</link>
		<comments>http://mandarin.no/as3/as3-snippet-3-remove-all-childs/#comments</comments>
		<pubDate>Sat, 02 May 2009 02:05:30 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[child]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[eventhandler]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[remove]]></category>
		<category><![CDATA[removeChild]]></category>
		<category><![CDATA[snippet]]></category>
		<guid isPermaLink="false">http://mandarin.no/?p=79</guid>
		<description><![CDATA[I code snippet I tend to use quite often. And one that I tend to forget how I wrote the last time i used it. while (this.numChildren &#62; 0) {     removeChild(this.getChildAt(0)); } Update: And when you want to remove a child as a part of an event handler, do this: event.target.parent.removeChild(event.target); Let&#8217;s say [...]]]></description>
			<content:encoded><![CDATA[<p>I code snippet I tend to use quite often. And one that I tend to forget how I wrote the last time i used it.</p>
<pre>while (this.numChildren &gt; 0)
{
    removeChild(this.getChildAt(0));
}</pre>
<p><strong>Update:</strong></p>
<p>And when you want to remove a child as a part of an event handler, do this:</p>
<pre>event.target.parent.removeChild(event.target);</pre>
<p>Let&#8217;s say you want to delete the button you just clicked. The button dispatches an event, and this line of code goes in the event handler. event.target is the button (or what ever object you clicked). It does look at bit strange, because you have to tell the button that it&#8217;s parent should delete the button. The button can&#8217;t delete itself.</p>
<p><strong>Note:</strong></p>
<p>If you&#8217;re working with Flex, use <span style="color: #333333;"><strong>this.removeAllChildren();</strong></span> Thank you Bjørnar <img src='http://mandarin.no/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/as3/as3-snippet-3-remove-all-childs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tips: Reading variables from Arduino using Flash, Flex or AIR</title>
		<link>http://mandarin.no/as3/tips-reading-variables-from-arduino-using-flash-flex-or-air/</link>
		<comments>http://mandarin.no/as3/tips-reading-variables-from-arduino-using-flash-flex-or-air/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 16:24:07 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[baud]]></category>
		<category><![CDATA[configure]]></category>
		<category><![CDATA[physical computing]]></category>
		<category><![CDATA[socket]]></category>
		<category><![CDATA[socket server]]></category>
		<guid isPermaLink="false">http://mandarin.no/?p=69</guid>
		<description><![CDATA[If you have experienced getting only gibberish from the Arduino when tracing it&#8217;s output using Flash, Flex or AIR, you might have misconfigured the socket server. I spent a whole day trying to figure out why I only got square boxes, a couple of random numbers and an occasional &#8216;f&#8217; now and then. I read [...]]]></description>
			<content:encoded><![CDATA[<p>If you have experienced getting only gibberish from the Arduino when tracing it&#8217;s output using Flash, Flex or AIR, you might have misconfigured the socket server.</p>
<p>I spent a whole day trying to figure out why I only got square boxes, a couple of random numbers and an occasional &#8216;f&#8217; now and then. I read somewhere that the configuration file for the socket server had to match the settings of the serial drivers. I didn&#8217;t pay much attention to it because I took it for granted that it was configured using a set of common settings. It turned out that I was wrong.</p>
<p>My drivers were set to 9600 baud, while my socket server ran at 19200 baud. Setting the socket server to 9600 baud solved all of my problems! Yes, all of them.</p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/as3/tips-reading-variables-from-arduino-using-flash-flex-or-air/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Actionscript: Outputting a grid using only one for-loop</title>
		<link>http://mandarin.no/as3/actionscript-outputting-a-grid-using-only-one-for-loop/</link>
		<comments>http://mandarin.no/as3/actionscript-outputting-a-grid-using-only-one-for-loop/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 20:44:09 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[column]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[modulo]]></category>
		<category><![CDATA[modulus]]></category>
		<category><![CDATA[row]]></category>
		<guid isPermaLink="false">http://mandarin.no/?p=18</guid>
		<description><![CDATA[Sometime this winter a friend of mine (Knut Urdalen) introduced me to a part of mathematics called modular arithmetic. Now that is a nifty little thing. In modular arithmetic, or modulus if you like, numbers reset themselves when reaching a given limit. Modulus is also known as &#8220;clock arithmetic&#8221;, and the clock is a very [...]]]></description>
			<content:encoded><![CDATA[<p>Sometime this winter a friend of mine (<a href="http://www.urdalen.com/" target="_self">Knut Urdalen</a>) introduced me to a part of mathematics called <a href="http://mathworld.wolfram.com/ModularArithmetic.html" target="_self">modular arithmetic</a>. Now that is a nifty little thing.</p>
<p>In modular arithmetic, or modulus if you like, numbers reset themselves when reaching a given limit. Modulus is also known as &#8220;clock arithmetic&#8221;, and the clock is a very good example for explaining modulus.</p>
<p>A 12 hour clock has a limit of 12, making the hours reset at 12 o&#8217;clock. So instead of becoming 13, it simply jumps back to 1. The same thing happens with a 24 hour clock, but at 24 hours instead of 12. This is as simple as I would&#8217;ve explained it, but <a href="http://mathworld.wolfram.com/ModularArithmetic.html" target="_self">Wolfram</a> has a more in-depth article with links to further reading. I&#8217;m sure <a href="http://www.google.com/search?hl=en&amp;q=+Modular+Arithmetic" target="_self">Google</a> has even more.</p>
<p>In ActionScript you can use modulus like this: x = y % z. Which reads like &#8220;x is y modulus to z&#8221;.</p>
<p>Following the example of the clock we would have to do a modulus of 12 on the total numbers of hours since the beginning of time to get the current time. Why? Ever since we started keeping track of time the numbers of hours have kept increasing. Time never stops. So instead of saying &#8220;oh, the time is 87654826253745 hours&#8221;, we do a modulus of 12 on 87654826253745 and get 7. And by looking out of the window we can tell if it is morning or evening.</p>
<p>Modulus can however not be used to count the number of turns the hour hand has turned at 87654826253745 o&#8217;clock. It only knows when it has reached the limit, not how many times it has turned.</p>
<p>So, as you probably have guessed already modulus is a drop dead simple way of outputting grids. And this is how I would&#8217;ve made a grid of images:</p>
<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> _max:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">20</span>; <span style="color: #808080; font-style: italic;">// Total number of items</span>
<span style="color: #0066CC;">private</span> _rows:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">5</span>; <span style="color: #808080; font-style: italic;">// Items per row</span>
<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">_width</span>:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">100</span>;
<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">_height</span>:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">100</span>;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createGrid<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
       <span style="color: #000000; font-weight: bold;">var</span> ix:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;
        <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&amp;</span>lt;_max; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// Iterate through all items</span>
        <span style="color: #66cc66;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">var</span> col:<span style="color: #0066CC;">Number</span> = i <span style="color: #66cc66;">%</span> _rows;
                col==<span style="color: #cc66cc;">0</span> ? ++ix : <span style="color: #0066CC;">void</span>;
                x = ix <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">_width</span>;
                y = col <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">_height</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>
<p>Let&#8217;s look at each of the lines;<br />
01 : define max number of items in the grid<br />
02 : define max number of items in each row<br />
03 &amp; 04 : width and height of each of the items<br />
08 : x position of row &lt;em&gt;n&lt;/em&gt; (increases for each new row)<br />
09 : loop through all items<br />
11 : col is &#8216;current item&#8217; modulus to &#8216;items per row&#8217;<br />
12 : if col has reset, increase ix by one. Here we jump to the next column<br />
13 : place item at x position &#8216;ix * _width&#8217;<br />
14 : place item at y position &#8216;col * _height&#8217;</p>
<p>And that&#8217;s about it. Simple, right?</p>
<p>If anyone of a more mathematical kind of person discovers something wrong, or would&#8217;ve explained modulus in a better way, do arrest me. I&#8217;m still learning.</p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/as3/actionscript-outputting-a-grid-using-only-one-for-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making a YouTube-esque video player in Flex</title>
		<link>http://mandarin.no/as3/making-a-youtube-esque-video-player-in-flex/</link>
		<comments>http://mandarin.no/as3/making-a-youtube-esque-video-player-in-flex/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 11:44:15 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[buffering]]></category>
		<category><![CDATA[custom preloader]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[FLV]]></category>
		<category><![CDATA[MetadataReceived]]></category>
		<category><![CDATA[NetConnection]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[VideoDisplay]]></category>
		<guid isPermaLink="false">http://mandarin.no/as3/making-a-youtube-esque-video-player-in-flex/</guid>
		<description><![CDATA[Earlier this week I finished a project for one of our clients. The client produces quite lot of video content, and wanted a video player that could be embedded in other websites. This was a rather straight forward project where I got to use a lot of things I already knew. But still I learned [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier this week I finished a project for one of our clients. The client produces quite lot of video content, and wanted a video player that could be embedded in other websites. This was a rather straight forward project where I got to use a lot of things I already knew. But still I learned a few new things.</p>
<p>One of the requirements was the file size of the finished SWF. I&#8217;d like to keep it to a minimum with no preloading before the buffering starts. It has to look good, so some graphics will have to be included, but the video is what people wants to see. One of the tricks to reduce filesize and loading time is avoiding using container classes like the canvas, hbox, vbox and the likes. The container classes are handy and useful for laying out your components. But they contain a lot of functionality I didn&#8217;t need, and whenever you add a component to a container class, it will redraw itself. So the initialization process will be slower. (Note to self; put all components inn the container before you add it to stage. That will reduce number of redraws)</p>
<p>As a general rule; if all you need to do is place the component at a particular coordinate; try avoiding using container classes and rather use the x, y properties of the component itself. It is very tempting to let the container do the positioning for you, but with a few extra lines of code, you can most likely avoid using them.</p>
<p>So I discarded the thought of using any containers at all. So how do I approach the placement of the components? Well, first of all I need to find the dimensions of the FLV, and then place the control bar accordingly.</p>
<p>When I first started making Flex apps, I read a lot of articles about developing with Flex. One of them was about the application startup order. I realized that was a subject worth paying attention to, but never did. And all of my Flex apps so far have worked fine. But this time I started to understand the importance of knowing how your Flex app builds itself up.</p>
<p>The video player reads a few FlashVars at startup, one of them being the URL to the FLV. Now, the dimensions of the FLV can vary from file to file, so sending the width and height will only cause more work to be done server side. Flex (and Flash) have a very easy to use event for retrieving the meta data of a FLV. So I decided to keep the number of FlashVars down to a minimum, and rather rely on the MetadataReceived event.</p>
<p>The MetadataReceived event doesn&#8217;t fire until the first part of the FLV has been read. So, since the layout of the video player is waiting for the dimensions of the FLV, I have would have to put this function at the earliest possible stage of the creation process. Sounds easy, but there was one thing that I didn&#8217;t think would matter but did; buffer time.</p>
<p>I was thinking about implementing some kind of dynamic buffering routine to take in account of the various bandwith&#8217;s people have. But the video&#8217;s are rarely longer than 30 seconds and on an average of about 6-7MB. So I figured it would be sufficient to just set the buffering to about 25-30% of the total playtime. And so I did.</p>
<p>Now, what happends when you set the bufferTime property of the videoDisplay component to e.g. 5 seconds, is that videoDisplay will wait until the buffer is full before triggering the MetadataReceived event. I don&#8217;t see any logical reason for this, but that&#8217;s the way it is. The solution to this is simply setting the bufferTime to 0 at initialization. The MetadataReceived will then trigger immediately, giving me all of the details on the FLV I needed. In the event handler for the Metadata-event I simply adjust the bufferTime up to the desired level. It is important to set the autoplay attribute of the VideoDisplay to false, or else the video will try to play immediately since the buffertime is 0.</p>
<p>At this time I have all of the information I need for placing the control bar. In the event handler for MetadataReceived I simply set the control bar&#8217;s y parameter to the height of the video. And voila! The layout is finished, and it all happend withing a fraction of a second.</p>
<p>To give the viewer an indication of the buffertime, I simply used a ProgressBar component. And on top of that I put an HSlider for scrubbing. In retrospect I now see that the ProgressBar is overkill for this purpose. It features a lot of functionality I don&#8217;t use, and I could have managed to achieve the same result using a Sprite which I scale in width (just like with the good old preloaders we made when AS1 and 2 was the big thing).</p>
<p>I mentioned earlier that I didn&#8217;t want any preloading of the application. But Flex throws in a preloader no matter what. In many cases this is a blessing, because you don&#8217;t have to make it yourself. But in this case, it&#8217;s a fair bit annoying. I guess it has to be there because of the creation process, which can take a few seconds -even on tiny applications. So my only option was to make it not look like the standard Flex preloader. I found a few articles on customizing the Flex preloader which helped me. Luckily, this doesn&#8217;t take more than a second in this application, so I simply used the client&#8217;s logo as a preloader. No indication of any progress at all.</p>
<p>These are the few things I learned while working on this project, which will most likely help me attack my next project in a better and more efficient way. Now, there&#8217;s one more thing I&#8217;d like to make a note of. And that&#8217;s something I didn&#8217;t learn.</p>
<p>It seems to me the VideoDisplay component doesn&#8217;t have any events for when the file is not found. I use the debugger version of the Flash Player, and that throws me a large error message saying the file was not found. It would&#8217;ve been better (in terms of usability) for me to trace this error using events instead, and then outputting a message onscreen saying &#8220;file not found&#8221;, or even showing a video where someone says &#8220;Sorry, file not found. But you might want to look at these videos&#8230;&#8221;. I could probably have used NetConnection. If there are anyone out there with an idea, or even better; an answer to this, please leave a comment. I&#8217;d love to hear about it.</p>
<p>Resources<br />
<a href="http://livedocs.adobe.com/flex/3/html/help.html?content=layoutperformance_03.html">Flex 3 &#8211; startup order</a><br />
<a href="http://www.slideshare.net/dcoletta/optimizing-flex-applications">David Colettas slideshow on Flex optimization</a>. It&#8217;s only a slideshow, but there are a few good tips to pick up.<br />
<a href="http://blog.poweredbyhamsters.com/2007/10/02/optimizing-flex-apps.aspx">Powered By Hamsters</a> has a few good tips on optimizing a Flex app.</p>
<p><a href="http://www.alagad.com/go/blog-entry/skinning-with-flex-3-css-explorer">Alagad &#8211; Skinning with Flex 3 CSS Explorer</a><br />
<a href="http://www.adobe.com/devnet/flex/articles/skins_styles.html">Adobe Devnet &#8211; Using CS3 to design styles and skins for Flex 3</a><br />
<a href="http://livedocs.adobe.com/flex/3/html/help.html?content=skinning_3.html">Flex 3 Help &#8211; Applying skins</a>. Some code examples of how to add skins to your components</p>
<p><a href="http://www.onflex.org/ted/2006/07/flex-2-preloaders-swf-png-gif-examples.php">Ted Parick &#8211; Flex custom preloaders</a><br />
<a href="http://flexiblemyself.blogspot.com/2007/10/custom-preloader.html">FLEXibleMySelf &#8211; Custom Preloader (Flex 3)</a></p>
<p>Always helpful:<br />
<a href="http://livedocs.adobe.com/flex/3/langref/index.html">Flex 3 Language Reference</a><br />
<a href="http://examples.adobe.com/flex3/consulting/styleexplorer/Flex3StyleExplorer.html">Flex 3 Style Explorer</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/as3/making-a-youtube-esque-video-player-in-flex/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>totalTime and MetadataReceived from VideoDisplay object in Flex</title>
		<link>http://mandarin.no/as3/totaltime-and-metadatareceived-from-videodisplay-object-in-flex-2/</link>
		<comments>http://mandarin.no/as3/totaltime-and-metadatareceived-from-videodisplay-object-in-flex-2/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 16:53:15 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[bufferTime]]></category>
		<category><![CDATA[MetadataReceived]]></category>
		<category><![CDATA[totalTime]]></category>
		<category><![CDATA[VideoDisplay]]></category>
		<guid isPermaLink="false">http://mandarin.no/as3/totaltime-and-metadatareceived-from-videodisplay-object-in-flex-2/</guid>
		<description><![CDATA[Interesting (and more than a bit annoying) observation; neither the property totalTime or the event MetadataEvent.METADATA_RECEIVED will trigger unless the buffer is full. I just discovered this as I tried to dynamically set the bufferTime to be 30% of the total playtime (I calculate the bufferTime using totalBytes and bytesLoaded). But as I traced values [...]]]></description>
			<content:encoded><![CDATA[<p>Interesting (and more than a bit annoying) observation; neither the property totalTime or the event MetadataEvent.METADATA_RECEIVED will trigger unless the buffer is full.</p>
<p>I just discovered this as I tried to dynamically set the bufferTime to be 30% of the total playtime (I calculate the bufferTime using totalBytes and bytesLoaded). But as I traced values like totalTime, I noticed it would stay at -1 until the video started playing (in other words; the buffer was full). Just for the sake of curiosity I set up an eventlistener listening for the duration property of the MetadataReceived event object. Interesting enough it wouldn&#8217;t trigger until the buffer was full.</p>
<p>It has been filed as a bug at <a href="http://bugs.adobe.com/jira/browse/SDK-14948" target="_blank">Adobe&#8217;s Flex Bug and Issues Management System</a>.</p>
<p>Possible workaround:
<ol>
<li>set bufferTime to 0 at initialization (this would hopefully trigger the READY event (or MetadataReceived if you prefer)</li>
<p>
<li>catch the totalTime value</li>
<p>
<li>pause/stop the video</li>
<p>
<li>increase bufferTime (or skip number 3 and go directly to number 4. It might work?)</li>
<p></ol>
<p>Technorati Tags: <a class="performancingtags" href="http://technorati.com/tag/flex" rel="tag">flex</a>, <a class="performancingtags" href="http://technorati.com/tag/as3" rel="tag">as3</a>, <a class="performancingtags" href="http://technorati.com/tag/actionscript" rel="tag">actionscript</a>, <a class="performancingtags" href="http://technorati.com/tag/meta%20data" rel="tag">meta data</a>, <a class="performancingtags" href="http://technorati.com/tag/video" rel="tag">video</a>, <a class="performancingtags" href="http://technorati.com/tag/development" rel="tag">development</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/as3/totaltime-and-metadatareceived-from-videodisplay-object-in-flex-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AS3 Snippet #1: Copy text to clipboard</title>
		<link>http://mandarin.no/as3/as3-snippet-1-copy-text-to-clipboard/</link>
		<comments>http://mandarin.no/as3/as3-snippet-1-copy-text-to-clipboard/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 13:44:18 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[clipboard]]></category>
		<category><![CDATA[copy]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<guid isPermaLink="false">http://d2997367.u306.hosted.servetheworld.net/?p=3</guid>
		<description><![CDATA[A useful little snippet of code for when you want to copy text to the clipboard: System.setClipboard(source.text); Where &#8216;source&#8217; is the id of e.g. a text field.]]></description>
			<content:encoded><![CDATA[<p>A useful little snippet of code for when you want to copy text to the clipboard:</p>
<blockquote>
<pre>System.setClipboard(source.text);</pre>
</blockquote>
<p>Where &#8216;source&#8217; is the id of e.g. a text field.</p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/as3/as3-snippet-1-copy-text-to-clipboard/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>AS3 Snippet #2: Watch for changing properties</title>
		<link>http://mandarin.no/as3/as3-snippet-2-watch-for-changing-properties/</link>
		<comments>http://mandarin.no/as3/as3-snippet-2-watch-for-changing-properties/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 14:32:13 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[changewatcher]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[property]]></category>
		<guid isPermaLink="false">http://d2997367.u306.hosted.servetheworld.net/?p=4</guid>
		<description><![CDATA[Today I stumbled across a handy utility class called ChangeWatcher, which lives inside the mx.binding.utils package. It provides you with a handy way of watching other object&#8217;s properties. Here&#8217;s how it&#8217;s used: ChangeWatcher.watch(object, &#8220;property&#8221;, handler); Object &#8211; the object which owns the property &#8220;property&#8221; &#8211; the property you want to watch handler &#8211; the function [...]]]></description>
			<content:encoded><![CDATA[<p>Today I stumbled across a handy utility class called ChangeWatcher, which lives inside the mx.binding.utils package. It provides you with a handy way of watching other object&#8217;s properties.</p>
<p>Here&#8217;s how it&#8217;s used:</p>
<blockquote><p>
ChangeWatcher.watch(object, &#8220;property&#8221;, handler);
</p></blockquote>
<p>Object &#8211; the object which owns the property<br />
&#8220;property&#8221; &#8211; the property you want to watch<br />
handler &#8211; the function name of the handler</p>
<p>Whenever the property of the object changes, the handler will respond. Quite handy, right?</p>
<p><em>edit:</em></p>
<p>Here&#8217;s an example for you:</p>
<p>Let&#8217;s say we have a class called WatchMe. Inside that class we have a public variable called ImBeingWatched. We&#8217;d like to trigger a function whenever this variable changes. To do this, we simply add one line of code:</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> mx.<span style="color: #006600;">binding</span>.<span style="color: #006600;">utils</span>.<span style="color: #66cc66;">*</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #66cc66;">*</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> WatchMe <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> ImBeingWatched:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">true</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> WatchMe<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			ChangeWatcher.<span style="color: #0066CC;">watch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #ff0000;">&quot;ImBeingWatched&quot;</span>, doSomething<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> doSomething<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// do something ...</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>
<p>As you can see, this works pretty much like using [Bindable] variables. But, in some cases this method proves quite handy.</p>
<p>Update: Oops! Typo. The property that ChangeWatcher is watching must be [Bindable] and Public for it to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/as3/as3-snippet-2-watch-for-changing-properties/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
