<?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>Professional Monkey Keyboard Operator</title>
	<atom:link href="http://www.pmko.net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.pmko.net</link>
	<description>one monkey&#039;s view of interactive development</description>
	<lastBuildDate>Thu, 01 Apr 2010 22:55:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Command line goodies</title>
		<link>http://www.pmko.net/linux/command-line-goodies</link>
		<comments>http://www.pmko.net/linux/command-line-goodies#comments</comments>
		<pubDate>Wed, 08 Jul 2009 08:32:38 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Code Example]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://localhost:9000/?p=214</guid>
		<description><![CDATA[Here are some command line tidbits that i use regularly and find to be very handy, hopefully you will too.
Create a list of files in a directory and all its subdirectories
find [path] -type f &#62; [output file]
example for listing all files in the directory source:
find source -type f &#62; files.txt
Monitor cpu usage
top -F -ocpu -s [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some command line tidbits that i use regularly and find to be very handy, hopefully you will too.</p>
<p><strong>Create a list of files in a directory and all its subdirectories</strong><br />
find <em>[path]</em> -type f &gt; <em>[output file]</em><br />
example for listing all files in the directory source:<br />
find source -type f &gt; files.txt</p>
<p><strong>Monitor cpu usage</strong><br />
top -F -ocpu -s 5 -n 5</p>
<p><strong>Update Modification Date Recursively</strong><br />
find {dir} -exec touch {} \;</p>
<p><strong>backup a directory</strong><br />
rsync -av &#8211;delete <em>[src] [dest]</em></p>
<p><strong>search through your command line history<br />
</strong>history | grep -i &#8220;search string&#8221;<br />
this will output a list of history commands by history number that match your search, then use the history number to run that command again<br />
!<em>[history number]</em></p>
<p><strong>remove all .svn directories</strong><br />
find ./ -name &#8220;.svn&#8221; | xargs rm -Rf</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmko.net/linux/command-line-goodies/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embedding fonts in an ActionScript Project</title>
		<link>http://www.pmko.net/flash-flex/embedding-fonts-in-an-actionscript-project</link>
		<comments>http://www.pmko.net/flash-flex/embedding-fonts-in-an-actionscript-project#comments</comments>
		<pubDate>Thu, 18 Jun 2009 08:08:31 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code Example]]></category>
		<category><![CDATA[Flash/Flex]]></category>

		<guid isPermaLink="false">http://localhost:9000/?p=197</guid>
		<description><![CDATA[Working with ActionScript projects can offer some rather interesting challenges with some of the most basic parts of Flash development. Things like preloading your application and using linked MovieClips from a library, not to mention using embedded fonts in your TextFields. This really becomes interesting when you want to use more than one font in [...]]]></description>
			<content:encoded><![CDATA[<p>Working with ActionScript projects can offer some rather interesting challenges with some of the most basic parts of Flash development. Things like preloading your application and using linked MovieClips from a library, not to mention using embedded fonts in your TextFields. This really becomes interesting when you want to use more than one font in a single TextField. And sure you can embed font files right into the AS class, but that doesn&#8217;t always work. I&#8217;ve had numerous issues with OTF fonts.</p>
<p>The method that I have had the best success with is using the same technique as embedding symbols from Flash AS2 swfs.  Here&#8217;s a step-by-step on how to do this.<br />
<span id="more-197"></span><br />
1) Create a new FLA and set to publish to Flash 9 / AS2.<br />
<div id="attachment_201" class="wp-caption aligncenter" style="width: 424px"><img src="http://localhost:9000/wp-content/uploads/2009/06/embed_step1.jpg" alt="FLA publish settings" title="embed_step1" width="414" height="313" class="size-full wp-image-201" /><p class="wp-caption-text">FLA publish settings</p></div></p>
<p>2) Create a New Font in the Library.<br />
<div id="attachment_203" class="wp-caption aligncenter" style="width: 460px"><img src="http://localhost:9000/wp-content/uploads/2009/06/embed_step2.jpg" alt="Exporting the font" title="embed_step2" width="450" height="148" class="size-full wp-image-203" /><p class="wp-caption-text">create new library font</p></div></p>
<p>3) Set the Linkage to export for ActionScript on the first frame.<br />
<div id="attachment_204" class="wp-caption aligncenter" style="width: 460px"><img src="http://localhost:9000/wp-content/uploads/2009/06/embed_step3.jpg" alt="export the font" title="embed_step3" width="450" height="272" class="size-full wp-image-204" /><p class="wp-caption-text">export the font</p></div></p>
<div id="attachment_205" class="wp-caption aligncenter" style="width: 374px"><img src="http://localhost:9000/wp-content/uploads/2009/06/embed_step3-5.jpg" alt="your new font in the library" title="embed_step3-5" width="364" height="181" class="size-full wp-image-205" /><p class="wp-caption-text">your new font in the library</p></div>
<p>4) Publish the swf to a directory within your project.<br />
<div id="attachment_206" class="wp-caption aligncenter" style="width: 380px"><img src="http://localhost:9000/wp-content/uploads/2009/06/embed_step4.jpg" alt="put your files in the right place" title="embed_step4" width="370" height="185" class="size-full wp-image-206" /><p class="wp-caption-text">put your files in the right place</p></div></p>
<p>5) Set non-embeded files to not copy to bin<br />
<div id="attachment_207" class="wp-caption aligncenter" style="width: 511px"><img src="http://localhost:9000/wp-content/uploads/2009/06/embed_step5.jpg" alt="Flex Builder compiler settings" title="embed_step5" width="501" height="175" class="size-full wp-image-207" /><p class="wp-caption-text">Flex Builder compiler settings</p></div></p>
<p>6) Associate a standard Embed meta tag with a property of the class.<br />
7) Create a new StyleSheet.<br />
8) Create a style with fontFamily set to the name of the embedded symbol.<br />
8) Assign the StyleSheet</p>

<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;">Sprite</span>;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.<span style="color: #004993;">AntiAliasType</span>;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.<span style="color: #004993;">StyleSheet</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.text</span>.<span style="color: #004993;">TextFieldAutoSize</span>;
&nbsp;
    <span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;450&quot;</span>, <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;60&quot;</span>, <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;#CCCCCC&quot;</span>, <span style="color: #004993;">frameRate</span>=<span style="color: #990000;">&quot;30&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> EmbeddedFonts extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _style<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">StyleSheet</span>;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _copy<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">TextField</span>;
&nbsp;
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;/embed/fonts.swf&quot;</span>,symbol=<span style="color: #990000;">&quot;Myriad Pro&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> MyriadPro<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Class</span>;
&nbsp;
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;/embed/fonts.swf&quot;</span>,symbol=<span style="color: #990000;">&quot;Myriad Pro Bold&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> MyriadProBold<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Class</span>;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> EmbeddedFonts<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> main<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Object</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            main.<span style="color: #004993;">fontSize</span> = <span style="color: #000000; font-weight:bold;">30</span>;
            main.<span style="color: #004993;">letterSpacing</span> = <span style="color: #000000; font-weight:bold;">8</span>;
            main.textAlign = <span style="color: #990000;">&quot;center&quot;</span>;
            main.<span style="color: #004993;">color</span> = <span style="color: #990000;">&quot;#FFFFFF&quot;</span>;
            main.fontFamily = <span style="color: #990000;">&quot;Myriad Pro&quot;</span>;
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> main_bold<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Object</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            main_bold.<span style="color: #004993;">fontSize</span> = <span style="color: #000000; font-weight:bold;">30</span>;
            main_bold.<span style="color: #004993;">letterSpacing</span> = <span style="color: #000000; font-weight:bold;">8</span>;
            main_bold.textAlign = <span style="color: #990000;">&quot;center&quot;</span>;
            main_bold.<span style="color: #004993;">color</span> = <span style="color: #990000;">&quot;#000000&quot;</span>;
            main_bold.fontFamily = <span style="color: #990000;">&quot;Myriad Pro Bold&quot;</span>;
&nbsp;
            _style = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">StyleSheet</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            _style.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;.main&quot;</span>, main<span style="color: #000000;">&#41;</span>;
            _style.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;.main_bold&quot;</span>, main_bold<span style="color: #000000;">&#41;</span>;
&nbsp;
            _copy = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_copy<span style="color: #000000;">&#41;</span>;
            _copy.<span style="color: #004993;">autoSize</span> = <span style="color: #004993;">TextFieldAutoSize</span>.<span style="color: #004993;">LEFT</span>;
            _copy.<span style="color: #004993;">embedFonts</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
            _copy.<span style="color: #004993;">selectable</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
            _copy.<span style="color: #004993;">mouseWheelEnabled</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
            _copy.<span style="color: #004993;">styleSheet</span> = _style;
            _copy.<span style="color: #004993;">htmlText</span> = <span style="color: #990000;">&quot;&lt;span class='main'&gt;I &lt;/span&gt;&lt;span class='main_bold'&gt;LIKE &lt;/span&gt;&lt;span class='main'&gt;MONKEYS!&lt;/span&gt;&quot;</span>;
            _copy.<span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">450</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">-</span> _copy.<span style="color: #004993;">textWidth</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>;
            _copy.<span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">-</span> _copy.<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;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>9) And voila.<br />
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="EmbeddedFonts" width="450" height="60" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"><param name="movie" value="/wp-content/uploads/2009/07/EmbeddedFonts.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#cccccc" /><param name="allowScriptAccess" value="sameDomain" /><embed src="/wp-content/uploads/2009/07/EmbeddedFonts.swf" quality="high" bgcolor="#cccccc" width="450" height="60" name="EmbeddedFonts" align="middle" play="true" loop="false" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmko.net/flash-flex/embedding-fonts-in-an-actionscript-project/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Recording and streaming video with FMS, Flex and AS3</title>
		<link>http://www.pmko.net/flash-flex/recording-and-streaming-video-with-fms-flex-and-as3</link>
		<comments>http://www.pmko.net/flash-flex/recording-and-streaming-video-with-fms-flex-and-as3#comments</comments>
		<pubDate>Thu, 21 May 2009 08:01:10 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code Example]]></category>
		<category><![CDATA[Flash/Flex]]></category>

		<guid isPermaLink="false">http://localhost:9000/?p=193</guid>
		<description><![CDATA[For some reason all of the code examples for using FMS are in AS2. Converting the examples to AS3 can be a bit challenging, especially since there is one really key piece of information that is left out that is new to AS3 and specific to the use of FMS2. The problem is the that [...]]]></description>
			<content:encoded><![CDATA[<p>For some reason all of the code examples for using FMS are in AS2. Converting the examples to AS3 can be a bit challenging, especially since there is one really key piece of information that is left out that is new to AS3 and specific to the use of FMS2. The problem is the that FMS2 only supports AMF0, but in AS3 the default setting for the NetConnection class&#8217; defaultObjectEncoding property is AMF3. Without changing this setting to AMF0, your code will seem to be correct, but will fail to connect without really telling you why. Check out the class that I created from the Adobe example and the MXML to use it.<br />
<span id="more-193"></span></p>

<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.events</span>.<span style="color: #000000; font-weight: bold;">*</span>;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.media</span>.<span style="color: #004993;">Microphone</span>;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.media</span>.<span style="color: #004993;">Camera</span>;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.media</span>.<span style="color: #004993;">Video</span>;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #004993;">NetConnection</span>;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #004993;">NetStream</span>;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.VideoDisplay;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> StreamingFLV extends <span style="color: #004993;">EventDispatcher</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> cam<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Camera</span>;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> mic<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Microphone</span>;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> rtmp<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> nc<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">NetConnection</span>;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> ns<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">NetStream</span>;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> local_video<span style="color: #000000; font-weight: bold;">:</span>VideoDisplay;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _rtmp<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _source<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> StreamingFLV<span style="color: #000000;">&#40;</span>_lv<span style="color: #000000; font-weight: bold;">:</span>VideoDisplay,_r<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>,_s<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            _rtmp = _r;
            _source = _s;
&nbsp;
            cam = <span style="color: #004993;">Camera</span>.<span style="color: #004993;">getCamera</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            cam.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">ActivityEvent</span>.<span style="color: #004993;">ACTIVITY</span>, activityHandler<span style="color: #000000;">&#41;</span>;
            cam.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">StatusEvent</span>.<span style="color: #004993;">STATUS</span>, handleCameraStatus<span style="color: #000000;">&#41;</span>;
&nbsp;
            mic = <span style="color: #004993;">Microphone</span>.<span style="color: #004993;">getMicrophone</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            mic.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">ActivityEvent</span>.<span style="color: #004993;">ACTIVITY</span>, activityHandler<span style="color: #000000;">&#41;</span>;
            mic.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">StatusEvent</span>.<span style="color: #004993;">STATUS</span>, handleCameraStatus<span style="color: #000000;">&#41;</span>;
&nbsp;
            local_video = _lv;
&nbsp;
            <span style="color: #004993;">NetConnection</span>.<span style="color: #004993;">defaultObjectEncoding</span> = <span style="color: #004993;">flash.net</span>.<span style="color: #004993;">ObjectEncoding</span>.<span style="color: #004993;">AMF0</span>;
            nc = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">NetConnection</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            nc.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">NetStatusEvent</span>.<span style="color: #004993;">NET_STATUS</span>, netStatusHandler<span style="color: #000000;">&#41;</span>;
            nc.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">SecurityErrorEvent</span>.<span style="color: #004993;">SECURITY_ERROR</span>, securityErrorHandler<span style="color: #000000;">&#41;</span>;
            nc.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">IOErrorEvent</span>.<span style="color: #004993;">IO_ERROR</span>, ioErrorHandler<span style="color: #000000;">&#41;</span>;
            nc.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">AsyncErrorEvent</span>.<span style="color: #004993;">ASYNC_ERROR</span>, asyncErrorHandler<span style="color: #000000;">&#41;</span>;
            nc.<span style="color: #004993;">connect</span><span style="color: #000000;">&#40;</span>_rtmp<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> startRecordFLV<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>
            local_video.<span style="color: #004993;">attachCamera</span><span style="color: #000000;">&#40;</span>cam<span style="color: #000000;">&#41;</span>;
            ns.<span style="color: #004993;">attachAudio</span><span style="color: #000000;">&#40;</span>mic<span style="color: #000000;">&#41;</span>;
            ns.<span style="color: #004993;">attachCamera</span><span style="color: #000000;">&#40;</span>cam<span style="color: #000000;">&#41;</span>;
            ns.<span style="color: #004993;">publish</span><span style="color: #000000;">&#40;</span>_source, <span style="color: #990000;">&quot;record&quot;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> stopRecordFLV<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>
            ns.<span style="color: #004993;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            local_video.<span style="color: #004993;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> startPlayback<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>
            local_video.<span style="color: #004993;">source</span> = _rtmp <span style="color: #000000; font-weight: bold;">+</span><span style="color: #990000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">+</span> _source <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;.flv&quot;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> stopPlayback<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>
            local_video.<span style="color: #004993;">close</span><span style="color: #000000;">&#40;</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> connectStream<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>
            ns = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">NetStream</span><span style="color: #000000;">&#40;</span>nc<span style="color: #000000;">&#41;</span>;
            ns.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">NetStatusEvent</span>.<span style="color: #004993;">NET_STATUS</span>, netStatusHandler<span style="color: #000000;">&#41;</span>;
            ns.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">AsyncErrorEvent</span>.<span style="color: #004993;">ASYNC_ERROR</span>, asyncErrorHandler<span style="color: #000000;">&#41;</span>;
            ns.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">SecurityErrorEvent</span>.<span style="color: #004993;">SECURITY_ERROR</span>, securityErrorHandler<span style="color: #000000;">&#41;</span>;
            ns.<span style="color: #004993;">client</span> = <span style="color: #0033ff; font-weight: bold;">this</span>;
&nbsp;
            <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onVideoReady&quot;</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> handleCameraStatus<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">StatusEvent</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;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;handleCameraStatus: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> event<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> activityHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">ActivityEvent</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;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;activityHandler: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> event<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> netStatusHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">NetStatusEvent</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;">trace</span><span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">info</span>.<span style="color: #004993;">code</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">info</span>.<span style="color: #004993;">code</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;NetConnection.Connect.Success&quot;</span><span style="color: #000000; font-weight: bold;">:</span>
                    connectStream<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                    <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Connected&quot;</span><span style="color: #000000;">&#41;</span>;
                    <span style="color: #0033ff; font-weight: bold;">break</span>;
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;NetStream.Play.StreamNotFound&quot;</span><span style="color: #000000; font-weight: bold;">:</span>
                    <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;No Connection!&quot;</span><span style="color: #000000;">&#41;</span>;
                    <span style="color: #0033ff; font-weight: bold;">break</span>;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> securityErrorHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">SecurityErrorEvent</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;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;securityErrorHandler: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> event<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> ioErrorHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">AsyncErrorEvent</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;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;ioErrorHandler: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> event<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> asyncErrorHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">AsyncErrorEvent</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;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;asyncErrorHandler: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> event<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">onMetaData</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">info</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</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;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;metadata: duration=&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">info</span>.duration <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; width=&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">info</span>.<span style="color: #004993;">width</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; height=&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">info</span>.<span style="color: #004993;">height</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; framerate=&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">info</span>.framerate<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">onCuePoint</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">info</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</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;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;cuepoint: time=&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">info</span>.<span style="color: #004993;">time</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; name=&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">info</span>.<span style="color: #004993;">name</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; type=&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">info</span>.<span style="color: #004993;">type</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">onPlayStatus</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">info</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</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;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">info</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: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And now the MXML:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">    paddingTop=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #000000;">    paddingLeft=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #000000;">    paddingBottom=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #000000;">    paddingRight=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #000000;">    horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span></span>
<span style="color: #000000;">    verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span></span>
<span style="color: #000000;">    backgroundGradientAlphas=<span style="color: #ff0000;">&quot;[0,0]&quot;</span></span>
<span style="color: #000000;">    backgroundColor=<span style="color: #ff0000;">&quot;#CCCCCC&quot;</span></span>
<span style="color: #000000;">    applicationComplete=<span style="color: #ff0000;">&quot;init();&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">        &lt;![CDATA[</span>
<span style="color: #339933;">            import StreamingFLV;</span>
<span style="color: #339933;">            import flash.media.Camera;</span>
<span style="color: #339933;">            import flash.display.StageAlign;</span>
<span style="color: #339933;">            import flash.display.StageScaleMode;</span>
&nbsp;
<span style="color: #339933;">            private var rFLV:StreamingFLV;</span>
<span style="color: #339933;">            private var pFLV:StreamingFLV;</span>
<span style="color: #339933;">            private var isPlaying:Boolean = false;</span>
<span style="color: #339933;">            private var isRecording:Boolean = false;</span>
&nbsp;
<span style="color: #339933;">            private function init():void {</span>
<span style="color: #339933;">                stage.scaleMode = StageScaleMode.NO_SCALE;</span>
<span style="color: #339933;">                stage.align = StageAlign.TOP_LEFT;</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            private function initRecordStream():void {</span>
<span style="color: #339933;">                rFLV = new StreamingFLV(video_record,&quot;rtmp://los1aps-flash/zflv/test&quot;,&quot;recordSample&quot;);</span>
<span style="color: #339933;">                rFLV.addEventListener(&quot;onVideoReady&quot;,initUI);</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            private function initPlayStream():void {</span>
<span style="color: #339933;">                pFLV = new StreamingFLV(video_play,&quot;rtmp://los1aps-flash/zflv/test&quot;,&quot;recordSample&quot;);</span>
<span style="color: #339933;">                pFLV.addEventListener(&quot;onVideoReady&quot;,initUI);</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            private function recordToggle():void {</span>
<span style="color: #339933;">                if (!isPlaying) {</span>
<span style="color: #339933;">                    record.label = &quot;RECORDING&quot;;</span>
<span style="color: #339933;">                    rFLV.startRecordFLV();</span>
<span style="color: #339933;">                } else {</span>
<span style="color: #339933;">                    record.label = &quot;RECORD&quot;;</span>
<span style="color: #339933;">                    rFLV.stopRecordFLV();</span>
<span style="color: #339933;">                }</span>
<span style="color: #339933;">                isPlaying = !isPlaying;</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            private function playToggle():void {</span>
<span style="color: #339933;">                if (!isPlaying) {</span>
<span style="color: #339933;">                    play.label = &quot;PLAYING&quot;;</span>
<span style="color: #339933;">                    pFLV.startPlayback();</span>
<span style="color: #339933;">                } else {</span>
<span style="color: #339933;">                    play.label = &quot;PLAY&quot;;</span>
<span style="color: #339933;">                    pFLV.stopPlayback();</span>
<span style="color: #339933;">                }</span>
<span style="color: #339933;">                isPlaying = !isPlaying;</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            private function initUI(evt:Event):void {</span>
<span style="color: #339933;">                record.enabled = true;</span>
<span style="color: #339933;">                play.enabled = true;</span>
<span style="color: #339933;">            }</span>
<span style="color: #339933;">        ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HBox</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> horizontalAlign=<span style="color: #ff0000;">&quot;right&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VideoDisplay</span> id=<span style="color: #ff0000;">&quot;video_record&quot;</span> width=<span style="color: #ff0000;">&quot;320&quot;</span> height=<span style="color: #ff0000;">&quot;240&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;initRecordStream();&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> id=<span style="color: #ff0000;">&quot;record&quot;</span> label=<span style="color: #ff0000;">&quot;record&quot;</span> enabled=<span style="color: #ff0000;">&quot;false&quot;</span> click=<span style="color: #ff0000;">&quot;recordToggle();&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> horizontalAlign=<span style="color: #ff0000;">&quot;left&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VideoDisplay</span> id=<span style="color: #ff0000;">&quot;video_play&quot;</span> width=<span style="color: #ff0000;">&quot;320&quot;</span> height=<span style="color: #ff0000;">&quot;240&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;initPlayStream();&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> id=<span style="color: #ff0000;">&quot;play&quot;</span> label=<span style="color: #ff0000;">&quot;play&quot;</span> enabled=<span style="color: #ff0000;">&quot;false&quot;</span> click=<span style="color: #ff0000;">&quot;playToggle();&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:HBox</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmko.net/flash-flex/recording-and-streaming-video-with-fms-flex-and-as3/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Dispatching events between AS3 and AS2</title>
		<link>http://www.pmko.net/as3/dispatching-events-between-as3-and-as2</link>
		<comments>http://www.pmko.net/as3/dispatching-events-between-as3-and-as2#comments</comments>
		<pubDate>Sat, 09 May 2009 07:15:14 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code Example]]></category>

		<guid isPermaLink="false">http://localhost:9000/?p=171</guid>
		<description><![CDATA[Even though AS3 has been out for some time now, there are still situations when you will need to load an AS2 compiled SWF into an AS3 compiled SWF and communicate with it. What if you could simply dispatch an event and listen for it on the other side? That&#8217;s what sugarcookie&#8217;s ASBridge does.  [...]]]></description>
			<content:encoded><![CDATA[<p>Even though AS3 has been out for some time now, there are still situations when you will need to load an AS2 compiled SWF into an AS3 compiled SWF and communicate with it. What if you could simply dispatch an event and listen for it on the other side? That&#8217;s what <a href="http://code.google.com/p/sugarcookie/">sugarcookie</a>&#8217;s <a href="http://code.google.com/p/sugarcookie/source/browse/trunk/as3/sugarcookie-framework/sugarcookie/adapters/ASBridge.as">ASBridge</a> does.  Let&#8217;s see how it all works.<br />
<span id="more-171"></span><br />
ASBridge consists of 2 classes, ASBridge classes for both <a href="http://code.google.com/p/sugarcookie/source/browse/trunk/as2/sugarcookie/adapters/">AS2</a> and <a href="http://code.google.com/p/sugarcookie/source/browse/trunk/as3/sugarcookie-framework/sugarcookie/adapters/">AS3</a>. The core idea of ASBridge comes from the Adobe LiveDocs LocalConnection entry, check out the second paragraph where it says that AS 1,2, and 3 can communicate with each other using a LocalConnection, that&#8217;s where the magic is. Only thing to really be aware of is the 40kb limit on the amount of data that can be passed as arguments to the send() method.</p>
<p><strong>ASBridge Example</strong><br />
Demonstrates loading a AS2 SWF into an ActionScript 3 Project generated SWF and using ASBridge to send and receive events with data between AS3 and AS2.</p>

<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> sugarcookie.adapter.ASBridge;
    <span style="color: #0033ff; font-weight: bold;">import</span> sugarcookie.events.GenericEvent;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Loader</span>;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #004993;">URLRequest</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ASBridge_Example extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _adapter<span style="color: #000000; font-weight: bold;">:</span>ASBridge;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _loader<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Loader</span>;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ASBridge_Example<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            _adapter = ASBridge.getInst<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            _adapter.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onAdapterReady&quot;</span>,onAdapterReady<span style="color: #000000;">&#41;</span>;
&nbsp;
            _loader = <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>;
            _loader.<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>, onLoadComplete<span style="color: #000000;">&#41;</span>;
             <span style="color: #6699cc; font-weight: bold;">var</span> request<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">URLRequest</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;AS2_ASBridge.swf&quot;</span><span style="color: #000000;">&#41;</span>;
            _loader.<span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span>request<span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_loader<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> onLoadComplete<span style="color: #000000;">&#40;</span>evt<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>
            <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onLoadComplete: &quot;</span><span style="color: #000000; font-weight: bold;">+</span>evt.<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> onAdapterReady<span style="color: #000000;">&#40;</span>evt<span style="color: #000000; font-weight: bold;">:</span>GenericEvent<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;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;successfully received event with data from AS2&quot;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onAdapterReady: &quot;</span><span style="color: #000000; font-weight: bold;">+</span>evt.<span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
            _adapter.sendEvent<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onBridgeComm&quot;</span>,<span style="color: #000000;">&#123;</span>id<span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">&quot;test data&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><strong>AS2 ASBridge</strong><br />
Demonstrates sending and receiving events with data between AS2 and AS3 implemented as a class that is instantiated on the timeline of a Flash 8 Fla.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> sugarcookie.<span style="color: #006600;">adapter</span>.<span style="color: #006600;">ASBridge</span>;
<span style="color: #0066CC;">import</span> sugarcookie.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> AS2_ASBridge <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _adapter:ASBridge;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AS2_ASBridge<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        _adapter = ASBridge.<span style="color: #006600;">getInst</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        _adapter.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;onBridgeComm&quot;</span>,<span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
        _adapter.<span style="color: #006600;">sendEvent</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;onAdapterReady&quot;</span>,<span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">status</span>:<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onBridgeComm<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;successfully received event with data from AS3&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.pmko.net/as3/dispatching-events-between-as3-and-as2/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>http://localhost</title>
		<link>http://www.pmko.net/mac-os-x/http-localhost</link>
		<comments>http://www.pmko.net/mac-os-x/http-localhost#comments</comments>
		<pubDate>Thu, 30 Apr 2009 06:55:28 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Mac OS X]]></category>

		<guid isPermaLink="false">http://localhost:9000/?p=164</guid>
		<description><![CDATA[Having a local web server to test your web sites and applications is essential to your development environment. It is very easy to set-up numerous virtual hosts for each of your projects, which allows you to develop your interactive masterpieces in a close to real world implementation. There are actually many aspects of Flash development [...]]]></description>
			<content:encoded><![CDATA[<p>Having a local web server to test your web sites and applications is essential to your development environment. It is very easy to set-up numerous virtual hosts for each of your projects, which allows you to develop your interactive masterpieces in a close to real world implementation. There are actually many aspects of Flash development that will exhibit different behavior or not even work at all if not served from a valid domain and by golly localhost counts.  We&#8217;ll cover setting this up on Mac OS X 10.4, with additional notes on the differences with 10.5 at the end.<br />
<span id="more-164"></span><br />
The worst thing that can happen to a developer is deploying your site or application to the clients server and having it not work and it&#8217;s usually because it was tested only in Flash or by dragging your HTML file into a browser. All developers on my team are required to have an active local web server that they manage, which also makes it easy for me to track their development efforts in basically real-time. If you have a Mac, then you&#8217;re cool, but also already have everything installed that you&#8217;re going to need. Let&#8217;s get started.</p>
<p>The easiest way to do this with minimal fuss and muss is to do it though your Systems Preferences -> Sharing Preference panel. Click on the Services tab and select Personal Web Sharing from the list. Click start and there you go, Apache 1.3.33 is up and running. Your web site&#8217;s URL is displayed at the bottom, which is usually your computer&#8217;s IP address. You can also type in http://localhost to get there. The actual directory where you place files to be viewed at this URL is /Library/WebServer/Documents/. Anything you place in this directory can be viewed in any web browser, even IE6, just as if it were on a real grown up web server. Only other computers on your LAN will be able to access this web site, by IP only &#8211; not localhost, but that&#8217;s cool. You wouldn&#8217;t want to use your dev or personal computer to serve live sites anyway.</p>
<p>Ok, so you&#8217;ve got a single site up and running. Now if you&#8217;re like me you have a ton of projects that should be set-up this way. Time to get our hands dirty and dig into the Apache config file, enable the root user and a brief tutorial on managing your Apache install from the Terminal.</p>
<p>First off you have to enable your root user and give it a password if you haven&#8217;t done so already. Only the root user has permission to edit the Apache config file, so let&#8217;s start there. In your /Applications/Utilities folder you will find a program called NetInfo Manager. Go ahead and launch it. In the top menu bar click on Security -> Authenticate and type in your computer&#8217;s admin password. Now the Enable Root User option will be available so go ahead and do that, you&#8217;ll have to authenticate again, type in the new root password, click ok, then Security -> Deauthenticate for good measure and you&#8217;re done.</p>
<p>Now we can make the necessary changes to the Apache config file and start/stop/restart the web server from the Terminal. Be extremely careful when using the Terminal as the root user, you can cause some very serious damage to your computer if not used with knowledge and caution. Open the terminal and type the following (do not type the $ or # characters, they represent the command line prompt):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">su</span> -
Password: <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">type</span> <span style="color: #000000; font-weight: bold;">in</span> your new root password<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #666666; font-style: italic;"># vi /etc/httpd/httpd.conf</span></pre></div></div>

<p>Now your in the text editor vi which I will not discuss here, but believe me you will love to hate it. You can also use pico instead of vi which is a bit easier to use, but your sys admin will laugh at you if caught doing so. For now use the arrow keys to move up and down through the config file. Since we&#8217;re already here we might as well turn on PHP. Arrow down until you see the following line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#LoadModule php4_module        libexec/httpd/libphp4.so</span></pre></div></div>

<p>In the config file the # symbol represents a commented out line of text, same as using // in ActionScript or JavaScript. Right now you are in the browse mode of vi and are unable to edit text. Hit the i key to go into insert mode, move the cursor in front of the # symbol and hit the delete key to remove it. Hit the esc key to get back out of edit mode and now you have uncommented that line of text. Keep arrowing down until you find this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#AddModule mod_php4.c</span></pre></div></div>

<p>Do the same thing you just did to remove the # comment symbol. If at this point you feel you are struggling with vi, <a href="http://www.google.com/search?q=vi+tutorial&#038;ie=utf-8&#038;oe=utf-8&#038;aq=t&#038;rls=org.mozilla:en-US:official&#038;client=firefox-a">Google</a> it and there are a million vi tutorials online. Now that you have edited the config file to enable PHP lets go ahead and save, then test to make sure it&#8217;s going ok so far. To save in vi type :wq, this saves the file and quits vi. To just save and not quit type :w and to quit and not save type :q!</p>
<p>To make this take effect you need to restart Apache, but first lets check to make sure we haven&#8217;t saved a bad config. At the command prompt type the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># apachectl configtest</span></pre></div></div>

<p>If everything goes ok, you&#8217;ll see the following output: Syntax OK. Now use the up arrow key to see your previous commands until you see:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># vi /etc/httpd/httpd.conf</span></pre></div></div>

<p>then hit enter.</p>
<p>Now were back in the config file again. Scroll all the way to the bottom of the file where the VirtualHosts directive is. The best way to have multiple virtual hosts on your local computer, since you&#8217;re probably not part of a domain or if so have no access to the Domain Controller, is to set them up on ports. A virtual host URL running on a port looks like this: http://localhost:9000. You may have see this before because there all kinds of services running on other ports on your computer. If you have Tomcat set-up, it runs on port 8080 as an example. It is generally safe to pick port numbers in the 9000 and 10000 range. The secret to this kind of set-up is to be sure to configure a port based virtual host for the default server which runs on port 80. Here is an example of a VirtualHost configuration that includes the default host and a custom one. All of your custom VirtualHost can have root directories anywhere on your computer.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Listen <span style="color: #000000; font-weight: bold;">*</span>:<span style="color: #000000;">80</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>virtualhost <span style="color: #000000; font-weight: bold;">*</span>:<span style="color: #000000;">80</span><span style="color: #000000; font-weight: bold;">&gt;</span>
  DocumentRoot <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>WebServer<span style="color: #000000; font-weight: bold;">/</span>Documents
<span style="color: #000000; font-weight: bold;">&lt;/</span>virtualhost<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
Listen <span style="color: #000000; font-weight: bold;">*</span>:<span style="color: #000000;">9000</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>virtualhost <span style="color: #000000; font-weight: bold;">*</span>:<span style="color: #000000;">9000</span><span style="color: #000000; font-weight: bold;">&gt;</span>
  DocumentRoot <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>chris<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>sample<span style="color: #000000; font-weight: bold;">/</span>build<span style="color: #000000; font-weight: bold;">/</span>bin
<span style="color: #000000; font-weight: bold;">&lt;/</span>virtualhost<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Now write, save, test the config and restart &#8211; done. You now have the power to create tons of individual web sites on your own computer. Check out the <a href="http://www.macdevcenter.com/">Mac DevCenter</a> for more information on this subject.</p>
<p>For those of us still on Tiger (10.4.x) and want to upgrade to PHP5, check out <a href="http://www.entropy.ch/software/macosx/php/">Entropy&#8217;s</a> site for a super easy installer.</p>
<p>For those that are cool enough to be using Leopard (10.5.x) here are some updates to the above information.<br />
Enabling root user:<br />
enable root user using utilities/Directory Utility<br />
unlock to enable changes<br />
go to edit&#8211;>enable root password<br />
done.</p>
<p>Enable PHP5:<br />
It&#8217;s already installed, so nothing to do.</p>
<p>Config file locations:<br />
/etc/apache2/http.conf<br />
/etc/apache2/extras/httpd-vhost.conf</p>
<p>additional info on httpd.conf configuration:<br />
check out this blog post on <a href="http://bustoutsolutions.com/blog/2007/11/20/os-x-leopard-local-web-development-with-apache-and-php">Bust Out Solutions</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmko.net/mac-os-x/http-localhost/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The problem with dropTarget</title>
		<link>http://www.pmko.net/as3/the-problem-with-droptarget</link>
		<comments>http://www.pmko.net/as3/the-problem-with-droptarget#comments</comments>
		<pubDate>Sat, 18 Apr 2009 06:42:34 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code Example]]></category>

		<guid isPermaLink="false">http://localhost:9000/?p=158</guid>
		<description><![CDATA[While working on an application that has some drag and drop functionality, I noticed something very interesting about the dropTarget property of the Sprite class. It seems that the dropTarget returns the DisplayObject that is at the bottom of the display list which may not yield the result you are expecting. I added a MouseEvent.MOUSE_MOVE [...]]]></description>
			<content:encoded><![CDATA[<p>While working on an application that has some drag and drop functionality, I noticed something very interesting about the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Sprite.html#dropTarget">dropTarget</a> property of the Sprite class. It seems that the dropTarget returns the DisplayObject that is at the bottom of the display list which may not yield the result you are expecting. I added a MouseEvent.MOUSE_MOVE event listener to the Sprite being dragged and traced out the dropTarget to see what kind of result I would get.<br />
<span id="more-158"></span><br />
Instead of seeing the names of Sprite instances that were set-up on the timeline, the trace output was nothing but generic names such as instance42. The reason for this is that the object at the very bottom of the display list is not the Sprite that was created, but the contents of that Sprite such as a Shape or Bitmap. It seems that the Flash Player automatically creates a DisplayObject for these internal Sprite elements and assigns them a unique instance name. Tracing out the dropTarget.parent then reveals the DisplayObject that we&#8217;re looking for. One thing to note is that a Sprite that only has visual elements that were created with the drawing API will not exhibit this behavior.</p>
<p>There are a couple of other things to be aware of when using the dropTarget. First, setting the mouseEnabled or mouseChildren properties to false will not keep a DisplayObject from being assigned to the dropTarget property. Second, depth has no effect on the assignment of a DisplayObject to the dropTarget propery. Objects at a higher depth than the object being dragged will react the same way as those that are under it. Third and probably the most important is that the assignment of the value for the dropTarget property is that of the DisplayObject that is directly under the mouse and has nothing to do with the bounding box of the DisplayObject being dragged. Lastly, there are definitely situations where the dropTarget will be null, so be sure to check for that before trying to access properties of the dropTarget or you&#8217;ll get everyone&#8217;s favorite error &#8211; TypeError: Error #1009: Cannot access a property or method of a null object reference.</p>
<p>example:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
&nbsp;
dragee.<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>,mouseDownHandler<span style="color: #000000;">&#41;</span>;
dragee.<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>,mouseUpHandler<span style="color: #000000;">&#41;</span>;
<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>,mouseMoveHandler<span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> mouseDownHandler<span style="color: #000000;">&#40;</span>evt<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>
    dragee.<span style="color: #004993;">startDrag</span><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> mouseUpHandler<span style="color: #000000;">&#40;</span>evt<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>
    dragee.<span style="color: #004993;">stopDrag</span><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> mouseMoveHandler<span style="color: #000000;">&#40;</span>evt<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: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>dragee.<span style="color: #004993;">dropTarget</span><span style="color: #000000; font-weight: bold;">!</span>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>dragee.<span style="color: #004993;">dropTarget</span>.<span style="color: #004993;">name</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>May the Null Object be your Friend. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmko.net/as3/the-problem-with-droptarget/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Trace statements for PHP</title>
		<link>http://www.pmko.net/php/trace-statements-for-php</link>
		<comments>http://www.pmko.net/php/trace-statements-for-php#comments</comments>
		<pubDate>Thu, 12 Mar 2009 06:36:32 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Code Example]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://localhost:9000/?p=156</guid>
		<description><![CDATA[If you&#8217;re a Flash developer then you probably use trace() as an essential part of your development routine. Maybe you even wrote a custom logger application to get a peak into what&#8217;s happening with your Flash application. Point is that you like to see what&#8217;s going on behind the scenes.
Now you&#8217;ve moved on to the [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re a Flash developer then you probably use trace() as an essential part of your development routine. Maybe you even wrote a custom logger application to get a peak into what&#8217;s happening with your Flash application. Point is that you like to see what&#8217;s going on behind the scenes.</p>
<p>Now you&#8217;ve moved on to the big leagues and started connecting Flash to PHP to add server-side functionality to your application, but how do you see what&#8217;s happening with your PHP code? PHP has a little know feature called <a href="http://php.net/error_log">error_log()</a> that lets you output messages to your web server&#8217;s log file. By tailing your log files while running your application you essentially get trace statements from your PHP code! You can do this by opening your terminal if on a Mac or use something like <a href="http://www.cygwin.com/">cygwin</a> on Windows, change directories to where the log files are and run the tail command with the follow flag.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Welcome to Darwin<span style="color: #000000; font-weight: bold;">!</span>
colossus:~ chris$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>
colossus:<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>httpd chris$ <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-f</span> error_log
<span style="color: #7a0874; font-weight: bold;">&#91;</span>Tue Jun  <span style="color: #000000;">5</span> <span style="color: #000000;">22</span>:<span style="color: #000000;">31</span>:<span style="color: #000000;">11</span> <span style="color: #000000;">2007</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>error<span style="color: #7a0874; font-weight: bold;">&#93;</span> This is my trace statement from PHP<span style="color: #000000; font-weight: bold;">!</span></pre></div></div>

<p>Enjoy and happy PHP testing! </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmko.net/php/trace-statements-for-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a custom logging target</title>
		<link>http://www.pmko.net/flex/creating-a-custom-logging-target</link>
		<comments>http://www.pmko.net/flex/creating-a-custom-logging-target#comments</comments>
		<pubDate>Wed, 04 Mar 2009 05:59:05 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code Example]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[sugarcookie]]></category>

		<guid isPermaLink="false">http://localhost:9000/?p=148</guid>
		<description><![CDATA[I figured since I&#8217;m on the subject I would go ahead and create a custom logging target for sugarcookie and a companion logging app &#8211; LumberJack. This particular target sends log message objects over a LocalConnection to a basic logging console that will output them into a text field. Being able to see trace statements [...]]]></description>
			<content:encoded><![CDATA[<p>I figured since I&#8217;m on the subject I would go ahead and create a <a href="http://code.google.com/p/sugarcookie">custom logging target for sugarcookie</a> and a companion logging app &#8211; <a href="http://code.google.com/p/sugarcookie/source/browse/trunk/logger/LumberJack/">LumberJack</a>. This particular target sends log message objects over a LocalConnection to a basic logging console that will output them into a text field. Being able to see trace statements from a site running on any server, on any network can really help when debugging your application that is deployed somewhere besides your localhost. There are other tools out there that do this like <a href="http://www.realeyesmedia.com/redbug/">RED|Bug</a>, <a href="http://osflash.org/xray">Xray</a> or even <a href="http://www.sephiroth.it/firefox/flashtracer/">FlashTracer</a>, but this one is extremely simple and includes all the code so you can modify it to suit your needs.</p>
<p>First let&#8217;s create the new log target class by extending the existing <code>mx.logging.targets.LineFormattedTarget</code> Flex class. Then override the logEvent method with the functionality desired and you&#8217;re in business. Here&#8217;s how I did it:<br />
<span id="more-148"></span></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> sugarcookie.logger <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">StatusEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">AsyncErrorEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">SecurityErrorEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #004993;">LocalConnection</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.LogEvent;
	<span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.targets.LineFormattedTarget;
	<span style="color: #0033ff; font-weight: bold;">import</span> mx.utils.ObjectUtil;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> LogMessageDispatcherTarget extends LineFormattedTarget <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _conn<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">LocalConnection</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> LogMessageDispatcherTarget<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			_conn = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">LocalConnection</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                       _conn.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">StatusEvent</span>.<span style="color: #004993;">STATUS</span>, onStatus<span style="color: #000000;">&#41;</span>;
                       _conn.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">AsyncErrorEvent</span>.<span style="color: #004993;">ASYNC_ERROR</span>, onAsyncError<span style="color: #000000;">&#41;</span>;
                       _conn.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">SecurityErrorEvent</span>.<span style="color: #004993;">SECURITY_ERROR</span>, onSecurityError<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> override <span style="color: #339966; font-weight: bold;">function</span> logEvent<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>LogEvent<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>
			_conn.<span style="color: #004993;">send</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;_echo1&quot;</span>,<span style="color: #990000;">&quot;update&quot;</span>,<span style="color: #000000;">&#123;</span><span style="color: #004993;">level</span><span style="color: #000000; font-weight: bold;">:</span>event.<span style="color: #004993;">level</span>,category<span style="color: #000000; font-weight: bold;">:</span>event.<span style="color: #004993;">currentTarget</span>.category,<span style="color: #004993;">message</span><span style="color: #000000; font-weight: bold;">:</span>event.<span style="color: #004993;">message</span>,<span style="color: #004993;">time</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">this</span>.includeTime<span style="color: #000000;">&#125;</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> onStatus<span style="color: #000000;">&#40;</span>evt<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">StatusEvent</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;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onStatus Event: &quot;</span><span style="color: #000000; font-weight: bold;">+</span>ObjectUtil.<span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span>evt<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> onAsyncError<span style="color: #000000;">&#40;</span>evt<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">AsyncErrorEvent</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;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onAsyncError Event: &quot;</span><span style="color: #000000; font-weight: bold;">+</span>ObjectUtil.<span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span>evt<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> onSecurityError<span style="color: #000000;">&#40;</span>evt<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">SecurityErrorEvent</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;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onSecurityError Event: &quot;</span><span style="color: #000000; font-weight: bold;">+</span>ObjectUtil.<span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span>evt<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Building on the <a href="/flex/removing-trace-statements-from-flex-applications">previous post</a>, I have swapped out the TraceTarget for our new <a href="http://code.google.com/p/sugarcookie/source/browse/trunk/as3/sugarcookie-framework/sugarcookie/logger/LogMessageDispatcherTarget.as">LogMessageDispatcherTarget</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> applicationComplete=<span style="color: #ff0000;">&quot;init();&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">        &lt;![CDATA[</span>
<span style="color: #339933;">            import mx.logging.Log;</span>
<span style="color: #339933;">            import mx.logging.ILogger;</span>
<span style="color: #339933;">            import mx.logging.LogEventLevel;</span>
<span style="color: #339933;">            import sugarcookie.logger.LogMessageDispatcherTarget;</span>
&nbsp;
<span style="color: #339933;">            private var _log:ILogger;</span>
<span style="color: #339933;">            private var _loggerTarget:LogMessageDispatcherTarget;</span>
&nbsp;
<span style="color: #339933;">            private function init():void {</span>
<span style="color: #339933;">                _loggerTarget = new LogMessageDispatcherTarget();</span>
<span style="color: #339933;">                _loggerTarget.filters=[&quot;*&quot;];</span>
<span style="color: #339933;">                _loggerTarget.level = LogEventLevel.ALL;</span>
<span style="color: #339933;">                _loggerTarget.includeDate = false;</span>
<span style="color: #339933;">                _loggerTarget.includeTime = false;</span>
<span style="color: #339933;">                _loggerTarget.includeCategory = true;</span>
<span style="color: #339933;">                _loggerTarget.includeLevel = true;</span>
<span style="color: #339933;">                Log.addTarget(_loggerTarget);</span>
&nbsp;
<span style="color: #339933;">                _log = Log.getLogger(&quot;ExampleRemoteLogger&quot;);</span>
<span style="color: #339933;">                _log.info(&quot;Logging rocks, Yo!&quot;);</span>
<span style="color: #339933;">            }</span>
<span style="color: #339933;">        ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.pmko.net/flex/creating-a-custom-logging-target/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing trace() statements from Flex applications</title>
		<link>http://www.pmko.net/flex/removing-trace-statements-from-flex-applications</link>
		<comments>http://www.pmko.net/flex/removing-trace-statements-from-flex-applications#comments</comments>
		<pubDate>Fri, 27 Feb 2009 05:44:35 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code Example]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://localhost:9000/?p=142</guid>
		<description><![CDATA[Removing trace() from your code is a great way to optimize it and improve overall performance. This is easy enough to do in Flash by checking &#8220;Omit trace actions&#8221; in the Publish Settings window, but in Flex there is no such setting or compiler argument that I&#8217;ve seen. No worries, there is a solution.

Luckily Flex [...]]]></description>
			<content:encoded><![CDATA[<p>Removing trace() from your code is a great way to optimize it and improve overall performance. This is easy enough to do in Flash by checking &#8220;Omit trace actions&#8221; in the Publish Settings window, but in Flex there is no such setting or compiler argument that I&#8217;ve seen. No worries, there is a solution.<br />
<span id="more-142"></span><br />
Luckily Flex provides us with a logging framework in the <code>mx.logging</code> package. To implement logging within your application you have to specify targets that will get the log messages. One of the available targets is the TraceTarget. When you want to omit trace statements, just comment out the <code>Log.addTarget</code> call and that&#8217;s it. See the example below on how to implement tracing with the Flex logger.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> applicationComplete=<span style="color: #ff0000;">&quot;init();&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">        &lt;![CDATA[</span>
<span style="color: #339933;">            import mx.logging.Log;</span>
<span style="color: #339933;">            import mx.logging.ILogger;</span>
<span style="color: #339933;">            import mx.logging.LogEventLevel;</span>
<span style="color: #339933;">            import mx.logging.targets.TraceTarget;</span>
&nbsp;
<span style="color: #339933;">            private var _log:ILogger;</span>
<span style="color: #339933;">            private var _traceTarget:TraceTarget;</span>
&nbsp;
<span style="color: #339933;">            private function init():void {</span>
<span style="color: #339933;">                _traceTarget = new TraceTarget();</span>
<span style="color: #339933;">                _traceTarget.filters=[&quot;*&quot;];</span>
<span style="color: #339933;">                _traceTarget.level = LogEventLevel.ALL;</span>
<span style="color: #339933;">                _traceTarget.includeDate = false;</span>
<span style="color: #339933;">                _traceTarget.includeTime = false;</span>
<span style="color: #339933;">                _traceTarget.includeCategory = true;</span>
<span style="color: #339933;">                _traceTarget.includeLevel = true;</span>
<span style="color: #339933;">                Log.addTarget(_traceTarget);</span>
&nbsp;
<span style="color: #339933;">                _log = Log.getLogger(&quot;ExampleLogger&quot;);</span>
<span style="color: #339933;">                _log.info(&quot;Your tracing like a pro!&quot;);</span>
<span style="color: #339933;">            }</span>
<span style="color: #339933;">        ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.pmko.net/flex/removing-trace-statements-from-flex-applications/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mounting Windows shares on Linux</title>
		<link>http://www.pmko.net/linux/mounting-windows-shares-on-linux</link>
		<comments>http://www.pmko.net/linux/mounting-windows-shares-on-linux#comments</comments>
		<pubDate>Thu, 12 Feb 2009 05:23:41 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Code Example]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://localhost:9000/?p=137</guid>
		<description><![CDATA[Recently I had the need to back up my svn repositories root directory that lives on our Linux dev server to a Windows server. At first I tried to mount an NFS Windows share to my Linux box, but because we don&#8217;t have an NIS server I am not able to authenticate my Linux account [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I had the need to back up my svn repositories root directory that lives on our Linux dev server to a Windows server. At first I tried to mount an NFS Windows share to my Linux box, but because we don&#8217;t have an NIS server I am not able to authenticate my Linux account against my Windows account. Most of you developers out there that have to support yourselves will probably have this issue because most office IT infrastructures are Windows based which don&#8217;t always play nice with your Linux dev box. The answer to this wasn&#8217;t as straight forward as you might think, so I thought that I would share my solution.<br />
<span id="more-137"></span><br />
I ended up creating a folder on the Windows server and sharing it, although I did have to end up giving read/write permissions to Everybody. Our development environment is secure so I&#8217;m not worried about it, but otherwise this could get you in trouble with your sys admin. This is all the set-up that is necessary on the Windows side. Now lets flip over to the Linux box and set it up.</p>
<p>To mount the share you first have to edit the <a href="http://linux.about.com/od/commands/l/blcmdl5_fstab.htm">/ect/fstab</a> file which contains information about the file systems available and their mount options. Add the following line to the file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">//&lt;</span>windows server<span style="color: #000000; font-weight: bold;">&gt;/&lt;</span>name of share<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/&lt;</span>name of directory to <span style="color: #c20cb9; font-weight: bold;">mount</span> share to<span style="color: #000000; font-weight: bold;">&gt;</span> cifs <span style="color: #007800;">uid</span>=<span style="color: #000000; font-weight: bold;">&lt;</span>linux username<span style="color: #000000; font-weight: bold;">&gt;</span>,<span style="color: #007800;">credentials</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>cifspw,<span style="color: #007800;">domain</span>=<span style="color: #000000; font-weight: bold;">&lt;</span>name of domian<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000;">0</span> <span style="color: #000000;">0</span></pre></div></div>

<p>The line has several space separated fields:<br />
server/share, mount directory, filesystem type, mount options, dump, fsck</p>
<p>Next we need to create the directory <code>/mnt/</code><em><name of directory to mount share to></em> which the <code>mount</code> command will need to be successful. Then the last thing before we can mount the Windows share is to create the credentials file that we specified in the fstab file. In the /etc directory create the cifpw file.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># vi cifspw</span></pre></div></div>

<p>Then put your info in the cifspw file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">username</span>=<span style="color: #000000; font-weight: bold;">&lt;</span>windows server username<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #007800;">password</span>=<span style="color: #000000; font-weight: bold;">&lt;</span>windows server password<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>After that we are safe to mount the share:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># mount &lt;name of directory to mount share to&gt;/</span></pre></div></div>

<p>Now we&#8217;re ready to set-up the backup. This is a very simple daily rotating backup script.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># source directory to backup</span>
<span style="color: #007800;">SRCDIR</span>=<span style="color: #000000; font-weight: bold;">&lt;</span>path to directory to be backed up<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># destination directory to backup to</span>
<span style="color: #007800;">DESTDIR</span>=<span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/&lt;</span>name of directory to <span style="color: #c20cb9; font-weight: bold;">mount</span> share to<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># incremental directory</span>
<span style="color: #007800;">INCDIR</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>A<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># backup options</span>
<span style="color: #007800;">OPTS</span>=<span style="color: #ff0000;">&quot;-av --delete --force --ignore-errors&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># clears last week backup for current day</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>emptydir <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>emptydir
rsync <span style="color: #660033;">--delete</span> <span style="color: #660033;">-a</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>emptydir<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #007800;">$DESTDIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$INCDIR</span><span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">rmdir</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>emptydir
&nbsp;
<span style="color: #666666; font-style: italic;"># do the backup</span>
rsync <span style="color: #007800;">$OPTS</span> <span style="color: #007800;">$SRCDIR</span> <span style="color: #007800;">$DESTDIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$INCDIR</span></pre></div></div>

<p>Put this script in /etc/cron.daily and you&#8217;re done.<br />
You can find more information on mounting windows shares <a href="http://www.cyberciti.biz/tips/how-to-mount-remote-windows-partition-windows-share-under-linux.html">here</a>.<br />
And for additional rsync examples and the inspiration behind my backup script go <a href="http://samba.anu.edu.au/rsync/examples.html">here</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmko.net/linux/mounting-windows-shares-on-linux/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
