<?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>Dan&#039;s Drivelings &#187; Javascript</title>
	<atom:link href="http://www.tntechnohermit.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tntechnohermit.com</link>
	<description>Random Thoughts of a Techno-Hermit</description>
	<lastBuildDate>Thu, 01 Sep 2011 16:37:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Experimenting with HTML and Javascript development in Adobe AIR</title>
		<link>http://www.tntechnohermit.com/2010/11/01/experimenting-with-html-and-javascript-development-in-adobe-air/</link>
		<comments>http://www.tntechnohermit.com/2010/11/01/experimenting-with-html-and-javascript-development-in-adobe-air/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 14:13:01 +0000</pubDate>
		<dc:creator>Dan Skaggs</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Amateur Radio]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://dan.skaggsfamily.ws/?p=443</guid>
		<description><![CDATA[This is a rather long post detailing some of the things I learned this weekend while creating my first &#8220;real&#8221; Adobe AIR application that joins my love of programming with another hobby that I have enjoyed for several years. Those of you that know me very well might remember that one of my hobbies is [...]]]></description>
			<content:encoded><![CDATA[<p>This is a rather long post detailing some of the things I learned this weekend while creating my first &#8220;real&#8221; Adobe AIR application that joins my love of programming with another hobby that I have enjoyed for several years.</p>
<p>Those of you that know me very well might remember that one of my hobbies is amateur radio. There are many facets to the ham radio hobby and one of them that I&#8217;ve been involved with over the last few years combines radios and GPS data into a real-time position reporting system called Automatic Position Reporting System (APRS). To make a long story short, people equipped to use this system have specialized radios in their vehicles that read positional data from GPS units and transmit it out over certain frequencies periodically. Usually, these information packets eventually find their way to a series of servers that forward the data to connected clients for display on whatever mapping system the client has available locally.</p>
<p>This weekend, I spent some time creating an Adobe AIR application written in HTML and Javascript that connects to one of these servers and plots the position reports on a Google map. I haven&#8217;t had a chance to do much development with AIR up to now so I thought this would be a good exercise to see if I could create a usable solution.<br />
<span id="more-443"></span></p>
<p>The first hurdle was to create some method of translating the raw packet of information (which is a variable length string of text) into its component parts that I could then use. Below is an example of an APRS position report packet.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">KI4TDG-9&gt;APT407,WIDE1-1,WIDE2-2,qAR,N5AAA-1:!3546.23N/08654.00W&gt;069/000/A=000800</pre></div></div>

<p>This looks like a bunch of gibberish I know, but the data formats (there are multiple different types of packets that can be transmitted over the APRS system) are well documented.  I wound up creating a Javascript object called APRSPacketParser.js (original name I know, but it works) that had a method called parse() that accepted a raw APRS packet like the one above. This method then used other methods such as extractCall(), extractTimeStamp(), extractPosition() and so on to reduce the raw string into a series of values that I stored in another Javascript object called APRSPositionReport.js.  That took about 3 hours or so to write up. Because of the many different types of packet formats, the parser object still needs a lot of work, but for now it works on the 3 most common forms of position reports.</p>
<p>Once that was complete and tested, I created a regular HTML page to get my head around integrating with the Google maps javascript API.  Within no time, I was able to have a Google map in my HTML page, centered on my location with a custom zoom level set. Once the map was there, I began experimenting with parsing sample packets I had hard-coded into the page and using the location data stored in the resulting APRSPositionReport object to insert markers on the Google map.  So far so good and my total time so far was less than 4 hours worth of work. At this point I decided to quit for the night and try to tackle the AIR bits the next day.</p>
<p>Up to this point, all I&#8217;d really accomplished was proving that I could follow the instructions for using the Google maps API and that I could parse some sample packets into position reports.  I still had to make all that work inside AIR.  Upon creating a new AIR project, I put the HTML and javascript code that I&#8217;d been working on into the project and ran it, expecting to see a Google map pop up. Nope!  All I got was a blank screen and a message saying that the variable &#8220;google&#8221; was undefined. </p>
<p>After a couple hours of head scratching and research, I found out about AIR security sandboxes and found some example code on how to successfully use assets in your AIR application that are not part of the project itself. The examples showed how to use the ParentSandboxBridge and ChildSandboxBridge objects to essentially create an &#8220;API&#8221; between pages to allow data to be shared between two sandboxes with different security levels.  At this point, I had my empty Google map displaying inside my AIR application. With a little bit of bug fixing, the javascript code that I had used to create the markers on the map was working and I had 4 sample APRS packets parsed and plotted on the Google map. Total time to this point was somewhere around 7 hours.</p>
<p>Obviously, to be useful, the hard-coded position reports had to go and be replaced with a real-time stream of data from one of the APRS servers.  This part was probably the easiest thing I did all weekend. The socket class in AIR makes it absolutely simple to create a TCP socket connection to a server. To create a socket object, I used the following code. The first line creates the object and the remaining lines assign methods to listen to various events that happen with the socket connection.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//Set up socket object that we'll use later when the connect/disconnect </span>
<span style="color: #006600; font-style: italic;">//buttons are clicked</span>
socket <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> air.<span style="color: #660066;">Socket</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
socket.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span>air.<span style="color: #660066;">Event</span>.<span style="color: #000066;">CLOSE</span><span style="color: #339933;">,</span> closeHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
socket.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span>air.<span style="color: #660066;">Event</span>.<span style="color: #660066;">CONNECT</span><span style="color: #339933;">,</span> connectHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
socket.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span>air.<span style="color: #660066;">IOErrorEvent</span>.<span style="color: #660066;">IO_ERROR</span><span style="color: #339933;">,</span> ioErrorHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
socket.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span>air.<span style="color: #660066;">SecurityErrorEvent</span>.<span style="color: #660066;">SECURITY_ERROR</span><span style="color: #339933;">,</span> securityErrorHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
socket.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span>air.<span style="color: #660066;">ProgressEvent</span>.<span style="color: #660066;">SOCKET_DATA</span><span style="color: #339933;">,</span> socketDataHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I then created a button labeled &#8220;Connect&#8221; and set the onClick action to run the javascript method named connect().  The code for that method looked like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> connect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>socket.<span style="color: #660066;">connected</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    socket.<span style="color: #660066;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;second.aprs.net&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">20157</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    writeln<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;user NOCALL pass -1 vers AirPRS 0.01 filter r/35.625/-86.9847/150&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>			
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In my case I needed to connect to the server named &#8220;second.aprs.net&#8221; on port 20157.  The last line of that method uses the writeln() method to send a string of configuration data to the server over the socket connection telling it about the kind of data I want it to send me. The server sends a new line of data across the socket connection each time it receives a position report from an amateur station. At this point, all I had to do was fill in the body of the socketDataHandler() listener method to forward each packet to another method I created that uses the parser to parse the incoming string and dispatch a message to the map to create a marker with the information contained in the APRSPositionReport javascript object created from the raw packet.  Total time to this point was about 9 hours.</p>
<p>I spent another 3 or 4 hours adding error trapping and a &#8220;console&#8221; area to the application that got updated each time a new packet came in from the server so that I could see data flowing into the application.</p>
<p>All in all, I had around 12 hours or so of actual development time in creating a functional, though not very feature rich, application based on the Adobe AIR platform. If you care to take a look at what I&#8217;ve done or run the application, I&#8217;ve made the <a href="http://dan.skaggsfamily.ws/AirPRS/AirPRS.air">application</a> and the <a href="http://dan.skaggsfamily.ws/AirPRS/AirPRS.src.zip">source code</a> available for download.</p>
<p>Here&#8217;s a screenshot of what the application looks like after it&#8217;s been running for a bit to pull in some position reports (click on the image for the full-sized view).</p>
<p><a href="http://dan.skaggsfamily.ws/wp-content/uploads/2010/10/AirPRS-screenshot.png"><img src="http://dan.skaggsfamily.ws/wp-content/uploads/2010/10/AirPRS-screenshot-300x242.png" alt="" title="AirPRS-screenshot" width="300" height="242" class="aligncenter size-medium wp-image-449" /></a></p>
<p>I already have a list of things that I want to add to this such as a preferences pane so that you can set your own center map point, control the radius around the center that you want reports for and so on.  I want to use the built-in SQLite functions to store those values which will provide me with another learning opportunity with a different feature of AIR.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tntechnohermit.com/2010/11/01/experimenting-with-html-and-javascript-development-in-adobe-air/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Be careful with the &#8216;local&#8217; scope when migrating from CF8 to CF9</title>
		<link>http://www.tntechnohermit.com/2010/02/08/be-careful-with-the-local-scope-when-migrating-from-cf8-to-cf9/</link>
		<comments>http://www.tntechnohermit.com/2010/02/08/be-careful-with-the-local-scope-when-migrating-from-cf8-to-cf9/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 14:24:15 +0000</pubDate>
		<dc:creator>Dan Skaggs</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://dan.skaggsfamily.ws/?p=355</guid>
		<description><![CDATA[One of the really nice &#8220;fixes&#8221; included in ColdFusion 9 from a developer&#8217;s perspective is the inclusion of an implicit &#8220;local&#8221; variable scope into which variables created within the body of a &#60;cffunction&#62; tag are placed by default. Previously, developers had to manually add a &#8220;var&#8221; keyword to variables that should only exist within the [...]]]></description>
			<content:encoded><![CDATA[<p>One of the really nice &#8220;fixes&#8221; included in ColdFusion 9 from a developer&#8217;s perspective is the inclusion of an implicit &#8220;local&#8221; variable scope into which variables created within the body of a &lt;cffunction&gt; tag are placed by default. Previously, developers had to manually add a &#8220;var&#8221; keyword to variables that should only exist within the confines of the function.</p>
<p>One of the ways of simplifying this that gained some traction among various developers prior to the release of ColdFusion 9 was to &#8220;var&#8221; a single variable at the top of the function as an empty structure then store any additional variables needed in the function inside it. Many folks, myself included, named this structure &#8220;local&#8221; so that it would be readily apparent that the values inside were local to that function. This approach worked fine and dandy on ColdFusion 8 and below.<br />
<span id="more-355"></span></p>
<p>I recently migrated one of my clients to ColdFusion 9 and not long after the client started getting isolated reports from his people having javascript errors in a data management application that uses AJAX-driven forms talking to CFCs.  At first these were very isolated and we weren&#8217;t able to reproduce the error, but, as time went on, the reports became more widespread. As I was troubleshooting this over the weekend, I discovered that we were getting javascript errors when trying to interact with this RemoteFacade CFC about 40% of the time.</p>
<p>Using <a href="http://www.getfirebug.com" target="_blank">Firebug</a>, I was able to watch the results come back from ColdFusion and noticed a very odd trend. Approximately 60% of the time, the JSON returned from the remote CFC call was as expected. In the other 40%, one of the main data structure names was an arbitrary, machine-generated name instead of the name we had specified in the code.</p>
<p>Here is an example of what we were expecting in the JSON returned from the RemoteFacade.cfc method:</p>

<div class="wp_syntax"><div class="code"><pre class="json" style="font-family:monospace;">{&quot;DATA&quot;:{&quot;CANEDIT&quot;:true,&quot;RECORDDATA&quot;:{&quot;Field1&quot;:&quot;value1&quot;} } }</pre></div></div>

<p>This is an example of what we would get back from the same request when we would see the javascript errors</p>

<div class="wp_syntax"><div class="code"><pre class="json" style="font-family:monospace;">{&quot;___IMPLICITARRYSTRUCTVAR5&quot;:{&quot;CANEDIT&quot;:true,&quot;RECORDDATA&quot;:{&quot;Field1&quot;:&quot;value1&quot;} } }</pre></div></div>

<p>See the difference?  Our &#8220;DATA&#8221; key was named completely differently which caused javascript to throw some error saying that variableName.DATA did not exist.</p>
<p>After looking over the ColdFusion code for quite a while and doing some step debugging with <a href="http://www.fusion-debug.com" target="_blank">FusionDebug</a> I had an idea.  I changed all the function-specific structures I had been using from:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> local <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">structNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
   ....
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> local <span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>to:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> ret <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">structNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
   ....
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> ret <span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>Once I changed those throughout the code base and reinitialized my application, all the javascript errors that we&#8217;d been experiencing across multiple request types went completely away.</p>
<p>I have an unconfirmed theory that in using the name &#8220;local&#8221; for my structure, ColdFusion was sometimes getting &#8220;confused&#8221; on what to return&#8211;ColdFusion&#8217;s built-in local scope or the method-specific variable I had named local. I don&#8217;t really have any way to prove that beyond a shadow of a doubt, but when I made the change, all my errors went away, so I decided chalk it up as a lesson learned for future development and move on to the next problem.  Needless to say the client was happy that the issue was fixed and I can say I learned something that day.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tntechnohermit.com/2010/02/08/be-careful-with-the-local-scope-when-migrating-from-cf8-to-cf9/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>jQuery head-scratcher and lesson learned</title>
		<link>http://www.tntechnohermit.com/2010/02/01/jquery-head-scratcher/</link>
		<comments>http://www.tntechnohermit.com/2010/02/01/jquery-head-scratcher/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 15:42:02 +0000</pubDate>
		<dc:creator>Dan Skaggs</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ModelGlue]]></category>

		<guid isPermaLink="false">http://dan.skaggsfamily.ws/?p=343</guid>
		<description><![CDATA[As I mentioned in my last post, I&#8217;m working on a pet project in my spare time. It uses jQuery in various places including in the site design template that I purchased to use with the site. The template uses jQuery to expand and collapse menu items in the left sidebar to show sub items [...]]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in my <a href="http://www.tntechnohermit.com/2010/01/31/coldfusion-9-caching-settings-to-watch-out-for">last post</a>, I&#8217;m working on a pet project in my spare time. It uses <a href="http://www.jquery.com" target="_blank">jQuery</a> in various places including in the site design template that I purchased to use with the site. The template uses jQuery to expand and collapse menu items in the left sidebar to show sub items for that selection. Because of this, jQuery and a javascript file named custom.js was included in the template.  After breaking the template apart to work inside my <a href="http://www.model-glue.com" target="_blank">ModelGlue</a> application, I started implementing some other features that used jQuery with their own associated javascript files, one of which was <a href="http://cfuniform.riaforge.org" target="_blank">cfUniform</a>.</p>
<p>As soon as I put the cfUniform code into the page, I started getting javascript errors in the console pane of Firebug. The error would state something similar to &#8220;$(document) not a function&#8221; or &#8220;$ not a function&#8221;.  Now, I&#8217;ve not had a ton of experience with jQuery, but I have used several pre-built jQuery plugins in sites before and I had seen errors similar to this.  Normally this error is caused by one of two issues.  Either a) you&#8217;ve forgotten to include the script block to load the jQuery library or b) your code is loading the jQuery library twice.</p>
<p>I was able to use <a href="http://www.getfirebug.com" target="_blank">Firebug</a> to verify that I was indeed loading it and loading it only once but couldn&#8217;t for the life of me figure out why I was getting an error. Obviously cfUniform wasn&#8217;t really at fault (the error pointed to a line in one of the cfUniform javascript files) so I knew it had to be something on my side.  I did some searching on the phrase and found some discussions around jQuery&#8217;s noConflict() feature that allows you to reference jQuery with a notation other than using the familiar &#8220;$&#8221;.  </p>
<p>After reading for a while, I opened the custom.js file that came with the site template and found the code below:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">noConflict</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #006600; font-style: italic;">//contents snipped</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Since I&#8217;m not using any other javascript libraries in this application that might conflict with using the &#8220;$&#8221; to access jQuery, I removed the noConflict() line, but that didn&#8217;t fix my problem. On a hunch I did a search/replace through the custom.js file replacing &#8220;jQuery(&#8221; with &#8220;$(&#8221; so that references to the jQuery library in this file would be accessed with the same syntax as in all the other javascript files. Lo and behold, all my errors in Firebug&#8217;s console went away and CFUniform began behaving as expected.</p>
<p>While I don&#8217;t understand all the underpinnings of why this worked, I&#8217;ll take it as my &#8220;lesson for the day&#8221; that in the future I need to always make sure that all the various jQuery plugins and code that is used in my applications need to reference the jQuery library with the same syntax.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tntechnohermit.com/2010/02/01/jquery-head-scratcher/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Free and easy way to play MP3 files in your web pages</title>
		<link>http://www.tntechnohermit.com/2009/04/26/free-and-easy-way-to-play-mp3-files-in-your-web-pages/</link>
		<comments>http://www.tntechnohermit.com/2009/04/26/free-and-easy-way-to-play-mp3-files-in-your-web-pages/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 22:53:47 +0000</pubDate>
		<dc:creator>Dan Skaggs</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[mp3]]></category>

		<guid isPermaLink="false">http://dan.skaggsfamily.ws/?p=187</guid>
		<description><![CDATA[One of my current clients recently commissioned me to write a feature for their site that allows visitors to listen to snippets of MP3 tracks that they sell directly from within the product&#8217;s &#8220;detail&#8221; page. In my particular situation, one of the requirements was to use the design commissioned by a separate design firm. In [...]]]></description>
			<content:encoded><![CDATA[<p>One of my current clients recently commissioned me to write a feature for their site that allows visitors to listen to snippets of MP3 tracks that they sell directly from within the product&#8217;s &#8220;detail&#8221; page. In my particular situation, one of the requirements was to use the design commissioned by a separate design firm. In doing some research I found a few different open source methods of accomplishing this. The one that turned out to be the best fit for our situation was an Adobe Flash-based application called <a href="http://www.varal.org/media/niftyplayer/">NiftyPlayer</a>. </p>
<p>NiftyPlayer is a free, open source Flash file that you can embed into your page and play MP3 files without worrying about what audio player is installed on the visitor&#8217;s machine. The best part for my situation is that the player is completely controllable through Javascript. That means that I could completely &#8220;hide&#8221; the UI provided by the Flash file by setting the height and width of the Flash object to zero and use custom javascript methods to craft my page to do exactly what I wanted it to do.<br />
<span id="more-187"></span><br />
Having a Javascript API to the Flash player object means that you can simply added the following code toplay a track:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;#&quot;
  onClick=&quot;niftyPlayer('previewPlayer').loadAndPlay('fileName.mp3')&quot;&gt;
      Play
&lt;/a&gt;</pre></div></div>

<p>NiftyPlayer also provides a way to register different types of events and pass a reference to a custom block of Javascript code to be run with that event fires.  For example, you can register the &#8220;onPlay&#8221; event to change the source of an image on the page when a track starts playing and then register the &#8220;onStop&#8221; and/or &#8220;onSongOver&#8221; event to change it back when the track is either stopped manually or runs to completion.</p>
<p>Having this ability to completely hide the UI of the Flash object and control it with Javascript code was key for us as it allowed us to use NiftyPlayer in a design that had been created by an outside design firm without having to dive into the .fla file and update the colors, fonts etc originally used by the author. Using the Javascript API, I was able to control the source of an image (play and stop images) as well as update the CSS class of the div containing the currently playing track while it was playing and reset it back to its previous state when the user pressed the stop button or when the track finished playing.</p>
<p>Because of Flash&#8217;s near-ubiquitous install base, NiftyPlayer is a great option to easily add MP3 playback capability to your web application and know that it&#8217;ll &#8220;just work&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tntechnohermit.com/2009/04/26/free-and-easy-way-to-play-mp3-files-in-your-web-pages/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

