<?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>monkeyflash.com &#187; Tutorials</title>
	<atom:link href="http://monkeyflash.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://monkeyflash.com</link>
	<description>Greg Lunn's blog, with tutorials on Flash, CSS, ActionScript and more.</description>
	<lastBuildDate>Wed, 31 Dec 2008 18:13:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Custom Preloader in Flash CS3</title>
		<link>http://monkeyflash.com/tutorials/custom-preloader/</link>
		<comments>http://monkeyflash.com/tutorials/custom-preloader/#comments</comments>
		<pubDate>Mon, 21 Jan 2008 17:15:35 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Flash & ActionScript]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://beta.monkeyflash.com/?p=46</guid>
		<description><![CDATA[The ability to create a custom preloader is a must in any Flash developer&#8217;s toolbox, but the process is very different in ActionScript 3.0. External files are no longer loaded into a waiting empty movie clip on the stage like you might have done in earlier versions. Instead images, SWF files, and any other external [...]]]></description>
			<content:encoded><![CDATA[<p>The ability to create a custom preloader is a must in any Flash developer&#8217;s toolbox, but the process is very different in ActionScript 3.0. External files are no longer loaded into a waiting empty movie clip on the stage like you might have done in earlier versions. Instead images, SWF files, and any other external content are loaded using the Loader class. The process is different, but not difficult. Let&#8217;s put together a basic custom preloader that can be used in a Flash movie for loading external images or other SWF files.<span id="more-46"></span></p>
<p>Since I want to focus on the code, I&#8217;ve provided an example file to get you started. <a href="/files/preloader.zip">Download the example files</a>, and open preloader.fla.</p>
<h3>Getting started</h3>
<h4>1. Open preloader.fla and review its contents.</h4>
<p>Inside <strong>preloader.fla</strong>, you&#8217;ll notice that the stage is empty. That&#8217;s because we&#8217;re going to load an external file and display it here. We&#8217;re also going to use code to dynamically place the preloader on the stage and to remove it when loading is complete.</p>
<p>Press <strong>Ctrl-L</strong> to open the Library. Inside you&#8217;ll see two movie clips. The first, <strong>barMC</strong>, is a simple green rectangle that will be used to create a visual progress bar while our file is loading. Notice that the registration point of this shape is on the far left side. This shape will scale from that point as it grows. <strong>Preloader</strong> is a movie clip that will contain all of the pieces of our preloader. If you <strong>right-click</strong> (Ctrl-click on a Mac) on the Preloader movie clip in the Library and select <strong>Linkage&#8230;</strong> you will see that the checkbox for &#8220;<strong>Export for ActionScript</strong>&#8221; has been selected. This means that when the file runs, we can access this movie clip dynamically by its class name, &#8220;<strong>Preloader</strong>.&#8221;</p>
<p class="image"><img src="/images/preloader01.jpg" alt="The Linkage properties for the Preloader movie clip." /></p>
<p class="caption">The Linkage properties for the Preloader movie clip.</p>
<p><strong>Double-click</strong> on Preloader in the Library to open it. There are three layers in this timeline. The &#8220;<strong>text</strong>&#8221; layer contains the &#8220;Loading&#8221; text that will tell the user what percentage of the file has been downloaded. Notice that the text box has an instance name of &#8220;<strong>loading_txt</strong>.&#8221; The &#8220;<strong>bar</strong>&#8221; layer contains an instance of the barMC movie clip that will expand to visually indicate how much of the download has completed. The green bar has an instance name of &#8220;<strong>bar_mc</strong>.&#8221; The &#8220;<strong>frame</strong>&#8221; layer simply contains an open box shape. This is an extremely simple preloader &#8211; feel free to create your own graphics that will better match your project.</p>
<p class="image"><img src="/images/preloader02.gif" alt="The barMC movie clip has an instance name of bar_mc in the Properties inspector." /></p>
<p class="caption">The barMC movie clip has an instance name of bar_mc in the Properties inspector.</p>
<h4>2. Add ActionScript to load the external file.</h4>
<p>Return to the main timeline by clicking <strong>Scene 1</strong> under the timeline. Click in the first frame of the <strong>actions</strong> layer and press <strong>F9</strong> to open the <strong>Actions</strong> panel.  Begin by telling Flash what file you want to load. This can be any image or even another SWF file. I&#8217;ve included an (intentionally rather large) JPG file in the example files for you to use as practice.</p>
<p>The <strong>Loader</strong> class expects to receive a <strong>URLRequest</strong> pointing to the file you wish to load, so we&#8217;ll need to start by creating a new URLRequest for to the external file. We&#8217;ll also need to create an instance of the <strong>Loader</strong> class to begin. Add the following code to the Actions panel. (If you&#8217;re loading a different file that the example, replace &#8220;<code>large_image.jpg</code>&#8221; with the name of your file.)</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> myRequest:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;large_image.jpg&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> myLoader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<h4>3. Begin loading the external file.</h4>
<p>Tell the <strong>myLoader</strong> instance of the Loader class that we just created to begin loading the file with the next line:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">myLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>myRequest<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<h4>4. Create listeners to monitor the progress of the file.</h4>
<p>At this point in the code, Flash will begin loading the file. We want to create a few <strong>event listeners</strong> to monitor the progress. The first will run a function called <strong>showPreloader()</strong> that will place the Preloader movie clip on the stage. The second listener will run a function called <strong>showProgress()</strong> that will visually update the preloader bar and text to reflect the download progress. The third listener will run the function <strong>showContent()</strong>, which will remove the preloader and show the content once the download is complete.</p>
<p>The Loader class has a property called <strong>contentLoaderInfo</strong> that contains information about the file being loaded. Adding the listeners to this property allows us to monitor the download as it happens. Add the following code to the Actions panel:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">myLoader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">OPEN</span>,showPreloader<span style="color: #66cc66;">&#41;</span>;
myLoader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ProgressEvent.<span style="color: #006600;">PROGRESS</span>,showProgress<span style="color: #66cc66;">&#41;</span>;
myLoader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,showContent<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<h4>5. Create an instance of the Preloader movie clip.</h4>
<p>Before we can display the Preloader on the stage, we&#8217;ll need to create an <strong>instance</strong> of it in ActionScript, so that we can refer to it by name. We&#8217;ll call this new instance &#8220;<strong>myPreloader</strong>.&#8221; Add the next line to the Actions panel.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> myPreloader:Preloader = <span style="color: #000000; font-weight: bold;">new</span> Preloader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<h4>6. Create the showPreloader function to display the preloader.</h4>
<p>The first event listener above will run a function called <strong>showPreloader()</strong>. This function will place the myPreloader instance on the stage using <strong>addChild()</strong>. Then it will position the preloader in the center of the stage by modifying its <strong>x</strong> and <strong>y</strong> properties. (If you&#8217;d like your preloader to appear someplace else on the screen, you can modify these properties here.)</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> showPreloader<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	addChild<span style="color: #66cc66;">&#40;</span>myPreloader<span style="color: #66cc66;">&#41;</span>;
	myPreloader.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;
	myPreloader.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h4>7. Add the showProgress function to update the preloader as the download progresses.</h4>
<p>The function that handles the visual updates to our preloader is called <strong>showProgress()</strong>, and is called from the second listener each time the ProgressEvent <strong>PROGRESS</strong> is triggered, which is when additional data from the download is received. This function will calculate the percentage completed by dividing the number of bytes downloaded so far by the total number of bytes. It will update the text display to reflect that amount, multiplied by 100 and rounded to a whole number. Then the function will update the width of the progress bar by setting its width to the maximum width  multiplied by the percent loaded. (The maximum width in this case is 198 pixels &#8211; you might need to adjust this value if you created your own custom graphics.)</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> showProgress<span style="color: #66cc66;">&#40;</span>event:ProgressEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> percentLoaded:<span style="color: #0066CC;">Number</span> = event.<span style="color: #0066CC;">bytesLoaded</span><span style="color: #66cc66;">/</span>event.<span style="color: #0066CC;">bytesTotal</span>;
	myPreloader.<span style="color: #006600;">loading_txt</span>.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Loading - &quot;</span> + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span>percentLoaded <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;%&quot;</span>;
	myPreloader.<span style="color: #006600;">bar_mc</span>.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">198</span> <span style="color: #66cc66;">*</span> percentLoaded;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h4>8. Add the showContent function to display the file after it has been loaded.</h4>
<p>The last listener above will run the <strong>showContent()</strong> function once all of the bytes of the external file have been completely loaded. The showContent() function simply removes the preloader from the stage, and then adds the <strong>myLoader</strong> instance, making the loaded content appear.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> showContent<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	removeChild<span style="color: #66cc66;">&#40;</span>myPreloader<span style="color: #66cc66;">&#41;</span>;
	addChild<span style="color: #66cc66;">&#40;</span>myLoader<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h4>9. Test the preloader by simulating a download.</h4>
<p>To test the preloader, we will use Flash&#8217;s built-in bandwidth simulator. Previewing the file from our local drive will cause the content to be loaded almost instantly, and you will only see the preloader for a fraction of a second. By simulating a slower download speed, we can test the functionality of the preloader.</p>
<p>First test the movie by pressing <strong>Ctrl-Enter</strong>. If you do not have any errors, you will see your loaded content appear immediately.  To simulate a download, and to test the preloader, press <strong>CTRL-Enter a second time</strong>. Flash will reload the test movie, and then simulate a download of the content at a controlled speed. The default setting is a 56kbps modem, and will give you time to study the behavior of the preloader. It should slowly count up the percentage in the text box, and the progress bar should slowly grow. When the download is complete, your loaded content will display.</p>
<p class="image"><img src="/images/preloader03.gif" alt="The preloader in action." /></p>
<p class="caption">The preloader in action.</p>
<h3>What about loading the entire movie?</h3>
<p>How can you use this same technique to load the entire SWF file and not an external asset? One way is to create a &#8220;wrapper&#8221; swf that only contains your preloader and the code above. You can then load your main SWF file into this wrapper container, and avoid the need to add a preloader to an already-completed Flash file. This is a very efficient and easy way to add a preloader to any site.</p>
<p>As with all things in ActionScript, there are other methods as well, but some are more difficult and best saved for a future tutorial. :)</p>
<p>Here&#8217;s the completed code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> myRequest:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;large_image.jpg&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> myLoader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
myLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>myRequest<span style="color: #66cc66;">&#41;</span>;
&nbsp;
myLoader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">OPEN</span>,showPreloader<span style="color: #66cc66;">&#41;</span>;
myLoader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ProgressEvent.<span style="color: #006600;">PROGRESS</span>,showProgress<span style="color: #66cc66;">&#41;</span>;
myLoader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,showContent<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> myPreloader:Preloader = <span style="color: #000000; font-weight: bold;">new</span> Preloader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> showPreloader<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        addChild<span style="color: #66cc66;">&#40;</span>myPreloader<span style="color: #66cc66;">&#41;</span>;
        myPreloader.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;
        myPreloader.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> showProgress<span style="color: #66cc66;">&#40;</span>event:ProgressEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">var</span> percentLoaded:<span style="color: #0066CC;">Number</span> = event.<span style="color: #0066CC;">bytesLoaded</span><span style="color: #66cc66;">/</span>event.<span style="color: #0066CC;">bytesTotal</span>;
        myPreloader.<span style="color: #006600;">loading_txt</span>.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Loading - &quot;</span> + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span>percentLoaded <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;%&quot;</span>;
        myPreloader.<span style="color: #006600;">bar_mc</span>.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">198</span> <span style="color: #66cc66;">*</span> percentLoaded;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> showContent<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        removeChild<span style="color: #66cc66;">&#40;</span>myPreloader<span style="color: #66cc66;">&#41;</span>;
        addChild<span style="color: #66cc66;">&#40;</span>myLoader<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p class="flasource"><a href="/files/preloader.zip">Download the example files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://monkeyflash.com/tutorials/custom-preloader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding a Poster Frame to Flash Video</title>
		<link>http://monkeyflash.com/tutorials/poster-frame-for-flash-video/</link>
		<comments>http://monkeyflash.com/tutorials/poster-frame-for-flash-video/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 14:40:12 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Flash & ActionScript]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://beta.monkeyflash.com/?p=42</guid>
		<description><![CDATA[One of the new features of the video playback component in Flash CS3 is the ability to assign a preview image, or a poster frame, to an FLV to make it easier to position and adjust. However, this new feature comes with a footnote that reads, &#8220;The preview image is displayed at authoring time only. [...]]]></description>
			<content:encoded><![CDATA[<p>One of the new features of the video playback component in Flash CS3 is the ability to assign a preview image, or a poster frame, to an FLV to make it easier to position and adjust. However, this new feature comes with a footnote that reads, &#8220;The preview image is displayed at authoring time only. To generate a runtime preview image, use the export button and load the image back by writing your own ActionScript.&#8221; Unfortunately, the missing ActionScript is not included in the documentation. In this tutorial, I will show you one way to include a poster frame in front of a Flash video.<span id="more-42"></span></p>
<h3>What&#8217;s the plan?</h3>
<p>I&#8217;m going to add a video to my site using the Flash CS3 video playback component and one of the default skins. I want to create a preview, or poster, image that appears when the video is first loaded. The video should wait until the user clicks on either the poster image itself, or on the play button in the component controls to start playing. Then, the preview image should disappear while the video plays. Finally, once the video is complete, I&#8217;d like the preview image to reappear so that the process can be repeated.</p>
<p>To start you&#8217;ll need an <strong>FLV</strong> file. Any video will do, but I&#8217;ve included one in the example files to get you started. I&#8217;ve also included the finished file in case you&#8217;d like to refer to it later.</p>
<p class="flasource"><a href="http://www.monkeyflash.com/files/poster.zip">Download the example files</a></p>
<h3>Getting started</h3>
<h4>1. Begin by creating a new Flash document.</h4>
<p>For this tutorial, begin by creating a new Flash ActionScript 3.0 document. Set the dimensions to <strong>320 x 280</strong> pixels by clicking the <strong>Size</strong> button in the <strong>Properties</strong> Inspector. The included sample FLV is 320&#215;240, and I&#8217;m leaving an extra 40 pixels for the playback controls. Save this file as <strong>player.fla</strong> in the same folder as your FLV file.</p>
<h4>2. Import the FLV video file into Flash.</h4>
<p>Import the video by choosing <strong>File</strong> > <strong>Import</strong> > <strong>Import Video</strong>.  Click the <strong>Browse</strong> button, locate your FLV, and click <strong>Open</strong>. Click <strong>Next</strong>. Under the <strong>Deployment</strong> screen, keep the default setting and click <strong>Next</strong>. On the <strong>Skinning</strong> screen, select a playback skin and a color. I chose <em>&#8220;SkinUnderPlaySeekMute.swf&#8221;</em> and a dark gray color. Click <strong>Next</strong>, and then click <strong>Finish</strong>.</p>
<p class="image"><img src="/images/poster01.gif" alt="Select a playback skin and color." /></p>
<p class="caption">Select a playback skin and color.</p>
<blockquote><p><strong>Note:</strong> For a little more information about the Video Import wizard, as well as an easy way to make your Flash video play in full-screen mode, see the previous tutorial, <a href="http://www.monkeyflash.com/tutorials/full-screen-video/"><strong>Full-Screen Video in Flash CS3</strong></a>.</p></blockquote>
<p>You should now see the video in the stage. In fact, if you test the movie (press <strong>Ctrl-Enter</strong>) you can watch the video play. You&#8217;ll notice that the video begins playing immediately. We&#8217;ll change that and create our preview image next.</p>
<h4>3. Give the video component an instance name of myVideo.</h4>
<p>Click on the video on the stage to select it, and then give it an <strong>instance name</strong> of <code>myVideo</code> in the <strong>Properties</strong> inspector at the bottom of the screen. <strong>Don&#8217;t forget this step</strong>, or our code won&#8217;t be able to talk to the video later.</p>
<p class="image"><img src="/images/poster02.gif" alt="Adding an instance name in the Property inspector." /></p>
<p class="caption">Adding an instance name in the Property inspector.</p>
<h4>4. Change the video component&#8217;s autoPlay value to false.</h4>
<p>Click the <strong>Parameters</strong> tab in the <strong>Properties</strong> Inspector at the bottom of the screen. You&#8217;ll see several parameters specific to the playback component. To prevent the video from playing on its own, click to the right of <strong>autoPlay</strong> and set it to <code>false</code>.</p>
<p class="image"><img src="/images/poster03.gif" alt="Change the autoPlay value to false." /></p>
<p class="caption">Change the autoPlay value to false.</p>
<h3>Creating the preview image</h3>
<h4>5. Select the preview frame from the video.</h4>
<p>To select a preview frame from the video, <strong>double-click</strong> next to the <strong>preview</strong> parameter, where it says, &#8220;<code>None</code>.&#8221; A small version of the video will begin to play, and time code will be displayed underneath it. You&#8217;ll also see the note below the video reminding us that a preview image selected here will only be available in authoring mode. Yep, that&#8217;s why we&#8217;re here.</p>
<p>If you move the cursor over the video, small playback controls will appear that will allow you to move through the video. Press <strong>Pause</strong>, and then use the controls to choose a suitable frame to become the preview image.</p>
<p class="image"><img src="/images/poster04.jpg" alt="Selecting a preview frame." /></p>
<p class="caption">Selecting a preview frame.</p>
<h4>6. Export the frame as a PNG image file.</h4>
<p>Click <strong>Export</strong> to save the frame as a PNG file. Save the image as <strong>poster.png</strong> in the same folder as your FLV. Close the <em>&#8220;Select Preview Frame&#8221;</em> window.</p>
<h3>Importing the PNG and setting up the preview</h3>
<h4>7. Import the preview image PNG file to the stage.</h4>
<p>Select <strong>File</strong> &gt; <strong>Import</strong> &gt; <strong>Import to Stage&#8230;</strong> Browse to the poster.png image, and click <strong>Open</strong>. Importing the image into the Flash file ensures that it will be loaded within the SWF file, ready to display.</p>
<h4>8. Convert the image to a movie clip.</h4>
<p>Click on the image and press <strong>F8</strong> to convert it to a symbol. Name the symbol &#8220;<strong>PosterFrame</strong>&#8221; and choose <strong>Movie clip</strong> as the type. Click <strong>OK</strong>. Converting the bitmap image to a movie clip will allow us to customize its appearance to indicate to the user that they can click the image to start the video.</p>
<p class="image"><img src="/images/poster05.jpg" alt="Converting the image bitmap into a movie clip named PosterFrame." /></p>
<p class="caption">Converting the image bitmap into a movie clip named &#8220;PosterFrame.&#8221;</p>
<p>Optionally, you can edit the movie clip to include a button or any other visual cues that you&#8217;d like. I&#8217;m going to add large play button to make it obvious that this is a video waiting to be played.</p>
<h4>9. Add a play button or icon to the movie clip.</h4>
<p><strong>Double-click</strong> on the poster frame clip on the stage to edit it. From here, I&#8217;m going to add one of Flash&#8217;s pre-built buttons for simplicity, but of course you can create a button of your own to use here as well.</p>
<p>Choose <strong>Window</strong> &gt; <strong>Common Libraries</strong> &gt; <strong>Buttons</strong>. Open the &#8220;<strong>playback rounded</strong>&#8221; folder, and drag an instance of the &#8220;<strong>rounded green play</strong>&#8221; button onto the stage. You can use the <strong>Free Transform</strong> tool to resize the button and position it over the image. <strong>Close</strong> the &#8220;<em>Library – Buttons.fla</em>&#8221; panel.</p>
<p class="image"><img src="/images/poster06.jpg" alt="Adding a button to the poster frame clip." /></p>
<p class="caption">Adding a button to the poster frame movie clip.</p>
<h4>10. Give the movie clip an instance name of &#8220;myPoster&#8221;.</h4>
<p>Return to the main stage by clicking &#8220;<strong>Scene 1</strong>&#8221; underneath the timeline. Click on the PosterFrame movie clip on the stage, and in the Properties inspector, give it an instance name of &#8220;<strong>myPoster</strong>.&#8221;</p>
<p class="image"><img src="/images/poster07.gif" alt="Adding an instance name in the Property inspector." /></p>
<p class="caption">Adding an instance name in the Property inspector.</p>
<h3>Adding the ActionScript to make it work</h3>
<p>Ok, the busy work is over. Now it&#8217;s time to add the elusive ActionScript to make the poster frame show up. I&#8217;m sure there are several ways to do this, and maybe some even more efficient, but I&#8217;m going to show you what has worked reliably for me.</p>
<h4>11. Create a new actions layer.</h4>
<p>Create a new <strong>layer</strong> in the timeline, and rename it &#8220;<strong>actions</strong>&#8220;. Click the first frame of the actions layer, and press <strong>F9</strong> to open the <strong>Actions</strong> panel.</p>
<h4>12. Create a function called playMovie.</h4>
<p>The <strong>playMovie</strong> function is very simple. It will run when the user clicks on the poster frame, and will start the video. Add this code underneath the previous line:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> playMovie<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    myVideo.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h4>13. Create two functions to turn the preview image on or off.</h4>
<p>The easiest way to hide the preview movie clip is to change its <strong>visible</strong> property to <strong>false</strong>. This not only hides the movie clip from the display, but it also prevents the user clicking on the same clip again, essentially <em>disabling</em> the clip until we need it again. To bring the clip back, return its <strong>visible</strong> property to <strong>true</strong>. Add two more functions below the existing code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> showPosterFrame<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    myPoster.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">true</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> hidePosterFrame<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    myPoster.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h4>14. Add a CLICK event listener to the poster frame movie clip.</h4>
<p>Enter the following in the Actions panel:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">myPoster.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, playMovie<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This will create an event listener that tells Flash to run the <strong>playMovie()</strong> function when the user clicks anywhere on the poster frame.</p>
<h4>15. Toggle the visiblity of the poster frame by listening for video events.</h4>
<p>Now we need to turn the preview image on or off at the right time. The most reliable way to do this is to listen for a specific type of event called a video event that will be triggered by the playing FLV file. When the FLV begins to play, it will trigger a <strong>PLAYING_STATE_ENTERED</strong> event, and we should then remove the poster frame. When the FLV is finished, it will trigger a <strong>COMPLETE</strong> video event, and we will make the poster frame visible again.</p>
<p>Before we can use the <strong>Video Event</strong> class, we must import it. Add the following line <strong>AT THE TOP</strong> of the rest of the code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> fl.<span style="color: #0066CC;">video</span>.<span style="color: #006600;">VideoEvent</span>;</pre></div></div>

<p>Then, add event listeners to toggle the poster frame when the video plays and ends. Add these two lines at the bottom of the code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">myVideo.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>VideoEvent.<span style="color: #006600;">PLAYING_STATE_ENTERED</span>, hidePosterFrame<span style="color: #66cc66;">&#41;</span>;
myVideo.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>VideoEvent.<span style="color: #006600;">COMPLETE</span>, showPosterFrame<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<h4>16. Test the movie, and correct any errors.</h4>
<p>Test the movie now by pressing <strong>Ctrl-Enter</strong>. You should see your preview picture on the stage. When you click on the poster frame (or the play button in the video component) the poster frame will disappear and the FLV will begin to play, and when the video ends, the poster frame will reappear!</p>
<p>If you have any ActionScript errors, please carefully review the code and correct any typos.</p>
<p id="preview">If you have JavaScript enabled, you will see the example here.</p>
<p><script type='text/javascript' src='/swf/swfobject.js'></script><br />
<script type='text/javascript'>
var s1 = new SWFObject('/swf/posterframe.swf','player','320','280','9');
s1.addParam('allowscriptaccess','always');
s1.write('preview');
</script></p>
<p>That&#8217;s it! You&#8217;ve created a very functional preview image, or a poster frame, using just a little ActionScript and the built-in Flash video components. Here&#8217;s a look at the completed code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> fl.<span style="color: #0066CC;">video</span>.<span style="color: #006600;">VideoEvent</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> showPosterFrame<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    myPoster.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">true</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> hidePosterFrame<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    myPoster.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> playMovie<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    myVideo.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
myPoster.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, playMovie<span style="color: #66cc66;">&#41;</span>;
myVideo.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>VideoEvent.<span style="color: #006600;">PLAYING_STATE_ENTERED</span>, hidePosterFrame<span style="color: #66cc66;">&#41;</span>;
myVideo.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>VideoEvent.<span style="color: #006600;">COMPLETE</span>, showPosterFrame<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p class="flasource"><a href="http://www.monkeyflash.com/files/poster.zip">Download the example files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://monkeyflash.com/tutorials/poster-frame-for-flash-video/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Full-Screen Video in Flash CS3</title>
		<link>http://monkeyflash.com/tutorials/full-screen-video/</link>
		<comments>http://monkeyflash.com/tutorials/full-screen-video/#comments</comments>
		<pubDate>Tue, 10 Jul 2007 13:46:17 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Flash & ActionScript]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://beta.monkeyflash.com/?p=35</guid>
		<description><![CDATA[One of the best new features in Flash Player 9 is its ability to play video full-screen, using the same outside-the-browser technique you&#8217;ve seen on YouTube and other video sites. One click opens the video to the full width of your monitor with a black background, and even includes a message letting the user know [...]]]></description>
			<content:encoded><![CDATA[<p>One of the best new features in Flash Player 9 is its ability to play video full-screen, using the same outside-the-browser technique you&#8217;ve seen on <a href="http://www.youtube.com">YouTube</a> and other video sites. One click opens the video to the full width of your monitor with a black background, and even includes a message letting the user know that they can return to their desktop by pressing the <strong>Esc</strong> key. Here&#8217;s the best part: using Flash CS3, you can add full-screen capability to your Flash video without writing a single line of ActionScript, and with only a tiny change to your HTML. Let&#8217;s take a look at how easy it can be.<span id="more-35"></span></p>
<h3>Encode your video to FLV</h3>
<p>Even though Flash CS3 can encode your videos when you import them, I prefer to use the Flash Video Encoder for converting my video files to FLV. Using the Video Encoder allows you to encode several files at once using a queue, letting you continue to work in Flash while the conversion is completed. The original video file should be the highest quality possible, preferably uncompressed, and can be saved as .mov, .avi, .mpeg, or .wmv. I&#8217;ve already included an FLV for you in the <a href="http://www.monkeyflash.com/files/fullscreen.zip">example files</a>, but here&#8217;s how it was created.</p>
<p>Begin by pressing the <strong>Add…</strong> button in the Flash Video Encoder. Browse to the file that you wish to convert, and press <strong>Open</strong>. Although the default settings will usually produce acceptable results, it&#8217;s a good idea to adjust the quality settings, especially since this video will be shown full screen.</p>
<p>Click <strong>Settings…</strong>. Here you can adjust the encoding rates for video and audio, as well as crop and resize the video if necessary. Under the <strong>Video</strong> tab, medium or high quality will give you the best results full-screen. I usually reduce the <strong>frame rate</strong> to 15 FPS as well to keep the file size under control, but you can choose <code>Same as source</code> to leave the frame rate unchanged.</p>
<p class="image"><img src="http://www.monkeyflash.com/images/fullscreen1.gif" alt="Adjusting the compression settings for the FLV file." /></p>
<p class="caption">Adjusting the compression settings for the FLV file.</p>
<p>Under the <strong>Crop and Resize</strong> tab, it&#8217;s a good idea to resize your video to more reasonable dimensions if your original is very large. Typically, web video is encoded at <code>320x240</code> pixels, but if you are going to display video full-screen, you might consider <code>480x360</code> or even <code>640x480</code> pixels to provide the best quality. Keep in mind that larger dimensions equal much larger file sizes, and it might be a good idea to experiment to find the settings that work best for your project. For this example, I&#8217;m using <code>320x240</code> pixels for my video.</p>
<p>Press <strong>OK</strong> once you&#8217;ve made your changes. You can add more files to your queue in the same manner, duplicate the current job and change the settings, or press <strong>Start Queue</strong> to begin the conversion. This will create FLV files with the same names as your original media in the same folders, unless you specified otherwise.</p>
<h3>Importing video into Flash</h3>
<p>Once you have an FLV file, it&#8217;s time to bring it into Flash CS3. Create a new <strong>Flash File (ActionScript 3.0)</strong>. In the <strong>Properties</strong> inspector, click the <strong>Size</strong> button and adjust the document to be the same width as your video file, and the same height plus 40 pixels to leave room for the player controls. In the example here, that will be <code>320x280</code> pixels. Change the background color of the document to black. <strong>Save</strong> the Flash file in the same folder as your FLV.</p>
<p class="image"><img src="http://www.monkeyflash.com/images/fullscreen2.gif" alt="Adjusting the size of the Flash document in the Properties Inspector." /></p>
<p class="caption">Adjusting the size of the Flash document in the Properties Inspector.</p>
<h4>Import the FLV</h4>
<p>Choose <strong>File</strong> &gt; <strong>Import</strong> &gt; <strong>Import Video</strong>. Click <strong>Browse</strong>, find the FLV file you created earlier, and click <strong>OK</strong>. (If you didn&#8217;t create the FLV file beforehand, you could point to your original file as well. Flash will create the FLV at the end of this wizard, but you&#8217;ll have to wait on the process to complete before continuing.) Click <strong>Next</strong>.</p>
<p>On the <strong>Deployment</strong> screen, you can choose how the FLV file will be streamed to your viewers. Unless you subscribe to a Flash Streaming Service or own a Flash Media Server, you&#8217;ll likely select the first option, <code>Progressive download from a web server</code>. This will allow the viewer to begin playing the video as soon as it begins to load, instead of waiting for the full download to complete. Click <strong>Next</strong>.</p>
<p class="image"><img src="http://www.monkeyflash.com/images/fullscreen3.gif" alt="Select Progressive stream from a web server." /></p>
<p class="caption">Select Progressive stream from a web server.</p>
<p>On the <strong>Skinning</strong> screen, you can select a set of player buttons to use to control video playback. There are many different combinations, but to enable full-screen mode, select one with a full screen button. For this example, I&#8217;ve selected <code>SkinUnderPlaySeekFullscreen.swf</code>. You can also choose a color for the controls, and I&#8217;ve chosen a dark gray. Click <strong>Next</strong>.</p>
<p class="image"><img src="http://www.monkeyflash.com/images/fullscreen4.gif" alt="Choosing a playback skin with a full screen button and a color." /></p>
<p class="caption">Choosing a playback skin with a full screen button and a color.</p>
<p>You will see a summary of your selections, and you can go back and make any changes you want. Click <strong>Finish</strong> to complete the video import, and after a few moments, the video will appear on the stage. Click the video, and use the Properties inspector to adjust its <code>x</code> and <code>y</code> positions to <code>0</code>.</p>
<p class="image"><img src="http://www.monkeyflash.com/images/fullscreen5.gif" alt="Move the video to the top left corner of the stage." /></p>
<p class="caption">Move the video to the top left corner of the stage.</p>
<p><strong>Save</strong> the Flash file, and choose <strong>File</strong> &gt; <strong>Publish Settings</strong>. Make sure that <code>Flash (.swf)</code> and <code>HTML (.html)</code> are checked, then click <strong>OK</strong>. Choose <strong>File</strong> &gt; <strong>Publish Preview</strong> &gt; <strong>Default (HTML)</strong> to create the SWF and HTML files and preview them in a browser. You&#8217;ll notice that the video will play, but the full screen button won&#8217;t work yet. We need to make one minor change in the HTML page to enable full screen mode.</p>
<h3>Edit the HTML file</h3>
<p><strong>Open</strong> the HTML file that was created in your favorite HTML or text editor. There are three places that <code>allowFullScreen</code> will be set to false by default: once inside the <code>script </code>tags, and twice between the <code>noscript</code> tags, within the <code>object</code> and <code>embed</code> tags. Locate these three variables and change their values to <code>true</code>. </p>
<p class="image"><img src="http://www.monkeyflash.com/images/fullscreen6.gif" alt="Change the allowFullScreen value in the HTML file to true." /></p>
<p class="caption">Change the <code>allowFullScreen</code> value in the HTML file to true.</p>
<p><strong>Save</strong> the file and reload the HTML page in your browser. This time, when you click the full screen button, you&#8217;ll watch your video in complete full screen glory!</p>
<p id="preview">If you have JavaScript enabled, you will see the example here.</p>
<p><script type='text/javascript' src='/swf/swfobject.js'></script><br />
<script type='text/javascript'>
var s1 = new SWFObject('/swf/fullscreen.swf','player','320','280','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('autoplay','false');
s1.write('preview');
</script></p>
<p class="flasource"><a href="http://www.monkeyflash.com/files/fullscreen.zip">Download the demo files</a></p>
<h3>A few notes</h3>
<p>Remember when you upload the files to the server that all of the necessary files will need to be uploaded together: the HTML file, the SWF, the skin SWF file, the FLV, and the <code>AC_RunActiveContent.js</code> file that is used to embed the movie. </p>
<p>Also, if you would like to embed the video on a pre-existing HTML page, simply copy the code from the HTML page that Flash created (everything between the <code>body</code> tags) and paste it into the appropriate place in your existing page. Make sure that the other files are moved into the same folder as that page on the server as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://monkeyflash.com/tutorials/full-screen-video/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the Tween Class</title>
		<link>http://monkeyflash.com/tutorials/using-the-tween-class/</link>
		<comments>http://monkeyflash.com/tutorials/using-the-tween-class/#comments</comments>
		<pubDate>Tue, 03 Jul 2007 01:07:42 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Flash & ActionScript]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://beta.monkeyflash.com/?p=28</guid>
		<description><![CDATA[In the past, if you wanted to create a bouncing animation using code, you&#8217;d spend hours pouring over physics equations and adjusting variables until you got it just right. By using the Tween class instead, you can create the same effect with just a few lines of code, and skip the high school physics review. [...]]]></description>
			<content:encoded><![CDATA[<p>In the past, if you wanted to create a bouncing animation using code, you&#8217;d spend hours pouring over physics equations and adjusting variables until you got it just right. By using the Tween class instead, you can create the same effect with just a few lines of code, and skip the high school physics review. A recent project gave me a chance to play with the Tween class, a relatively obscure set of scripts that can be used to create varying programmatic animation.<span id="more-28"></span></p>
<blockquote><p><strong>Important note:</strong> This tutorial will be written using ActionScript 3 and Flash CS3.
</p></blockquote>
<h3>Understanding the Tween class</h3>
<p>The Tween class lets you move, resize, rotate, or fade a movieclip using only ActionScript. You can animate any property of a movieclip, such as <code>x</code>, <code>y</code>, <code>rotation</code>, <code>scaleX</code>, <code>scaleY</code>, and <code>alpha</code>. You can also specify how long the animation will last in either seconds or frames. The code will follow this example:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">new</span> Tween<span style="color: #66cc66;">&#40;</span>obj, prop, func, begin, finish, <span style="color: #0066CC;">duration</span>, useSeconds<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>The Tween constructor function accepts these parameters:</p>
<ol>
<li><strong>obj</strong> &#8211; The instance name of the movieclip that you want to animate.</li>
<li><strong>prop</strong> &#8211; The property of the movieclip that you want to change, such as x or alpha, as a text string.</li>
<li><strong>func</strong> &#8211; The type of easing you want to apply to the animation to change its acceleration.</li>
<li><strong>begin</strong> &#8211; The starting value of the property being animated.</li>
<li><strong>finish</strong> &#8211; The ending value of the property being animated.</li>
<li><strong>duration:</strong> &#8211; How long the animation will take, either in frames or seconds.</li>
<li><strong>useSeconds</strong> &#8211; If your duration is in seconds, set this to true. If your duration is in frames, set this to false.</li>
</ol>
<p>Before using the Tween class, you&#8217;ll need to import the classes into your code. Here&#8217;s what the ActionScript would look like to animate a banana movieclip from left to right across the stage within three seconds:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> fl.<span style="color: #006600;">transitions</span>.<span style="color: #006600;">Tween</span>;
<span style="color: #0066CC;">import</span> fl.<span style="color: #006600;">transitions</span>.<span style="color: #006600;">easing</span>.<span style="color: #66cc66;">*</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> myTween:Tween = <span style="color: #000000; font-weight: bold;">new</span> Tween<span style="color: #66cc66;">&#40;</span>banana_mc, <span style="color: #ff0000;">&quot;x&quot;</span>, Elastic.<span style="color: #006600;">easeOut</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">450</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Isn&#8217;t that much cleaner and easier that doing the math yourself? First, the two <code>import</code> lines make these classes available to us. Keep in mind that <code>import</code> statements must be at the top of all of your actions. Then we tell Flash to create a new Tween instance called <code>myTween</code>, and using the model above, we&#8217;re telling Flash to animate the movieclip <code>banana_mc</code> along the x axis, from position 50 to position 450 in three seconds. We&#8217;re using the <code>Elastic.easeOut</code> function, one of several options to control the acceleration of the animation. </p>
<p>Click the play button below to see the result:</p>
<p id="preview">If you have JavaScript enabled, you will see the example here.</p>
<p><script type='text/javascript' src='/swf/swfobject.js'></script><br />
<script type='text/javascript'>
var s1 = new SWFObject('/swf/tweenexample.swf','player','550','150','9');
s1.addParam('allowscriptaccess','always');
s1.write('preview');
</script></p>
<h3>Easing options</h3>
<p>The banana uses <code>Elastic.easeOut</code> to create an overshoot effect at the end of the animation, but there are several other options to add lifelike movement to your tweens. You can select an Easing class from these choices:</p>
<ul>
<li><strong>Back</strong> &#8211; Causes the animation to overshoot, and return to its position.</li>
<li><strong>Bounce</strong> &#8211; Causes the animation to reverse direction, like a ball bouncing on a floor.</li>
<li><strong>Elastic</strong> &#8211; Causes the animation to overshoot and reverse, like at the end of a rubber band.</li>
<li><strong>Regular</strong> &#8211; Accelerates along a steady curve.</li>
<li><strong>Strong</strong> &#8211; Accelerates along a steady curve, more aggressive than Regular.</li>
<li><strong>None</strong> &#8211; Results in no acceleration; a steady speed.</li>
</ul>
<p>Then, you pair any Easing class with an easing function to control which end of the tween (beginning, ending, or both) is affected:</p>
<ul>
<li><strong>easeIn</strong>  &#8211; The ease is applied to the beginning of the tween.</li>
<li><strong>easeInOut</strong> &#8211; The ease is applied to bothe the beginning and the end of the tween.</li>
<li><strong>easeOut</strong> &#8211; The ease is applied to the end of the tween.</li>
</ul>
<p>Combinations such as <code>Bounce.easeOut</code> or <code>Strong.easeIn</code> result in different effects. Click each of the buttons below to see the effect that each Easing class creates.</p>
<p id="preview2">If you have JavaScript enabled, you will see the example here.</p>
<p><script type='text/javascript' src='/swf/swfobject.js'></script><br />
<script type='text/javascript'>
var s1 = new SWFObject('/swf/easingClasses.swf','player2','550','220','9');
s1.addParam('allowscriptaccess','always');
s1.write('preview2');
</script></p>
<h3>Controlling Tween playback</h3>
<p>You can alter the Tween&#8217;s playback by using any of several methods:</p>
<ul>
<li><strong>continueTo(finish, duration)</strong> &#8211; Instructs the animation to continue tweening from its current animation point to a new finish and duration point.</li>
<li><strong>fforward()</strong> &#8211; Fast-forwards to the end of the animation.</li>
<li><strong>nextFrame()</strong> &#8211; Forwards a stopped animation to the next frame.</li>
<li><strong>prevFrame()</strong> &#8211; Reverses a stopped animation to its previous frame.</li>
<li><strong>resume()</strong> &#8211; Plays an animation that has been stopped.</li>
<li><strong>start()</strong> &#8211; Plays an animation from its begin value.</li>
<li><strong>stop()</strong> &#8211; stops the animation.</li>
<li><strong>yoyo()</strong> &#8211; Plays the animation in reverse.</li>
</ul>
<p>Flash will begin playing the animation the moment that the Tween is instantiated. Using the above code on its own would trigger the animation the instant that the animation is loaded, or the moment that the frame with the code is reached. If you would rather have the effect wait for some user input, such as a button click, you could stop the Tween, and then start it from within an Event handler, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">myTween.<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
play_btn.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, moveBanana<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> moveBanana<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	myTween.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h3>Allowing the Tween to trigger additional code</h3>
<p>The Tween class has several events that can be used to detect what the tween is currently doing:</p>
<ul>
<li><strong>MOTION_CHANGE</strong> &#8211; Indicates when the animation has changed.</li>
<li><strong>MOTION_FINISH</strong> &#8211; Indicated the animation is complete.</li>
<li><strong>MOTION_LOOP</strong> &#8211; Indicates the animation has started again in looping mode.</li>
<li><strong>MOTION_RESUME</strong> &#8211; Indicates that the animation has been resumes after being paused.</li>
<li><strong>MOTION_START</strong> &#8211; Indicates that the animation has started.</li>
<li><strong>MOTION_STOP</strong> &#8211; Indicates that the animation has stopped.</li>
</ul>
<p>For instance, you could reset the banana to its original position once the animation is complete. First, import the <code>TweenEvent</code> class using another import statement at the top of your code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> fl.<span style="color: #006600;">transitions</span>.<span style="color: #006600;">TweenEvent</span>;</pre></div></div>

<p>Then, add the following code to wait for the motion to finish and reset the <code>banana_mc</code> movieclip’s <code>x</code> value to 30.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">myTween.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>TweenEvent.<span style="color: #006600;">MOTION_FINISH</span>, handleReset<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> handleReset<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:TweenEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	banana_mc.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">30</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p class="flasource"><a href="/files/tweenclass.zip">Download the Demo FLA</a></p>
<p>For more information on the Tween class, please see the excellent Adobe documentation for <a href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#038;file=00000965.html">Flash CS3</a> or <a href="http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#038;file=00004142.html">Flash 8</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://monkeyflash.com/tutorials/using-the-tween-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Drag and Drop</title>
		<link>http://monkeyflash.com/tutorials/flash-drag-and-drop/</link>
		<comments>http://monkeyflash.com/tutorials/flash-drag-and-drop/#comments</comments>
		<pubDate>Thu, 14 Jun 2007 19:19:57 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Flash & ActionScript]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://beta.monkeyflash.com/?p=7</guid>
		<description><![CDATA[Creating drag and drop functionality in Flash CS3 is quite different than in older versions if you&#8217;re using the new ActionScript 3.0. While still relatively straightforward, the code can be a little more intimidating to users who are less familiar with ActionScript programming. If you&#8217;re like me, you&#8217;re here to try to keep your knowledge [...]]]></description>
			<content:encoded><![CDATA[<p>Creating drag and drop functionality in Flash CS3 is quite different than in older versions if you&#8217;re using the new ActionScript 3.0. While still relatively straightforward, the code can be a little more intimidating to users who are less familiar with ActionScript programming. If you&#8217;re like me, you&#8217;re here to try to keep your knowledge up-to-date, so let&#8217;s learn how to create a simple ActionScript 3.0 drag and drop game step-by-step. <a href="/files/dragdrop.zip">Download the FLA</a> and follow along with these steps.<span id="more-7"></span></p>
<h3>Setting up the Flash file</h3>
<p>Open <strong><a href="/files/dragdrop.zip">dragdrop.fla</a></strong> and review its organization. There are five layers in the file – one containing the &#8220;pegs&#8221; that we will drag and drop, one for the &#8220;targets&#8221; that we will drop the shapes onto, and one for the wooden box image. The text layer and the actions layer are currently empty. The pegs and the targets are movieclip symbols saved in the library. Press <strong>CTRL-L</strong> to view the library.</p>
<h4>1. Create a dynamic text field to display the right or wrong responses on the text layer.</h4>
<p>In order to provide the user with some feedback, we will display a message when the shapes are dropped, indicating whether or not they were placed successfully. Click <strong>frame 1</strong> of the <strong>text</strong> layer. Use the <strong>Text tool</strong> to draw a text box underneath the peg shapes. Type &#8220;<em>Put the shapes away!</em>&#8221; to give the box an initial message.</p>
<p class="image"><img src="http://www.monkeyflash.com/images/ddas301.gif" alt="Adding the dynamic text box." /></p>
<p class="caption">Adding the dynamic text box.</p>
<p>In the Properties inspector, change the text box to a <strong>Dynamic</strong> Text box using the drop down menu. Set the font to <strong>Arial bold</strong>, the font color to <strong>#990000</strong>, and the size to <strong>18pt</strong>. Give the text box an instance name of &#8220;<strong>reply_txt</strong>&#8220;. Use the Selection tool to position the text box if necessary.</p>
<p class="image"><img src="http://www.monkeyflash.com/images/ddas302.gif" alt="Setting the properties of the dynamic text box." /></p>
<p class="caption">Setting the properties of the dynamic text box.</p>
<h4>2. Assign instance names to the peg and target movie clips.</h4>
<p>In order to determine which target we drop our shapes over, we need to name them. Click the bright green pentagon target on the stage, and in the <strong>Properties</strong> inspector, give it an instance name of &#8220;<strong>targetpentagon_mc</strong>&#8220;. Repeat the process, giving the other three green targets instance names of &#8220;<strong>targetsquare_mc</strong>&#8220;, &#8220;<strong>targettriangle_mc</strong>&#8220;, and &#8220;<strong>targetflower_mc</strong>&#8220;. Take special note of the lowercase values &#8211; this will be important later.</p>
<p>Click the red square peg on the stage and give it an instance name of &#8220;<strong>square_mc</strong>&#8220;. Repeat the process, giving the other three colored pegs instance names of &#8220;<strong>flower_mc</strong>&#8220;, &#8220;<strong>triangle_mc</strong>&#8220;, and &#8220;<strong>pentagon_mc</strong>&#8220;.</p>
<p class="image"><img src="http://www.monkeyflash.com/images/ddas303.gif" alt="Adding an instance name to the pentagon target." /></p>
<p class="caption">Adding an instance name to the pentagon target.</p>
<blockquote><p><strong>Why are the targets so small?</strong><br />
The targets are smaller than the holes on the toy to provide a little more accuracy. Smaller targets mean that the shape has to be more closely lined up to register as a match.</p></blockquote>
<h4>3. Adjust the targets to make them invisible.</h4>
<p>Since the appearance of bright green targets spoils the illusion of a child&#8217;s toy, we will make them transparent. Using the <strong>Selection</strong> tool, click the first green target. Then, holding down <strong>Shift</strong> on the keyboard, click to select the other three targets. In the Properties inspector, choose <strong>Alpha</strong> from the <strong>Color</strong> dropdown menu. Then set the Alpha value to <strong>0</strong>, making the targets transparent.</p>
<p class="image"><img src="http://www.monkeyflash.com/images/ddas304.gif" alt="Setting the alpha value of the targets to zero." /></p>
<p class="caption">Setting the alpha value of the targets to zero.</p>
<h3>Adding Drag and Drop functionality</h3>
<p>Now it&#8217;s time to dive into the code. Since ActionScript 3.0 no longer uses <code>onPress</code> and <code>onRelease</code> events, we&#8217;ll need some new code to create the same effect.</p>
<h4>4. Add ActionScript to make the red square dragable.</h4>
<p>We&#8217;ll write some ActionScript to allow us to drag and drop the square peg. Select <strong>frame 1</strong> of the <strong>actions</strong> layer, and open the <strong>Actions</strong> panel by pressing <strong>F9</strong>. Type in the following actions:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">square_mc.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, pickUp<span style="color: #66cc66;">&#41;</span>;
square_mc.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, dropIt<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> pickUp<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    event.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">startDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> dropIt<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    event.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">stopDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
square_mc.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">true</span>;</pre></div></div>

<p class="image"><img src="http://www.monkeyflash.com/images/ddas305.gif" alt="Adding the drag and drop Actionscript." /></p>
<p class="caption">Adding the drag and drop Actionscript.</p>
<p>This tells Flash to begin dragging the movie clip when the user presses the mouse button, and stop when the mouse is released. In ActionScript 3.0, this is created by setting an event listener for each event, <code>MOUSE_DOWN</code> and <code>MOUSE_UP</code>, and assigning event handler functions (here called <code>pickUp</code> and <code>dropIt</code>) to tell Flash what to do once the event is triggered. Within these event handlers, <code>event.target</code> refers to the object that initiated this event, which in this case will be <code>square_mc</code>. Using <code>event.target</code> instead of naming the object specifically will let us reuse this code for all four pegs in a few steps. The &#8220;true&#8221; parameter of the <code>startDrag</code> function causes the shape to be picked up from its center, which will make it easier to place later. To display the hand cursor when clicking movieclip symbols, we set the <code>buttonMode</code> property to true. Press <strong>CTRL-Enter</strong> to test the movie, and try dragging the square.</p>
<h4>5. Add ActionScript to display a message in the text box when the peg is dropped.</h4>
<p>Here is where we determine where we release the peg, and provide feedback. Add the following code just below <code>event.target.startDrag(true);</code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">reply_txt.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;&quot;</span>;</pre></div></div>

<p>Adding this code inside the <code>pickUp</code> event handler will force the text inside the dynamic text field to clear when we pick up the peg.</p>
<p>Add the following lines below <code>event.target.stopDrag();</code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> myTargetName:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;target&quot;</span> + event.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">name</span>;
<span style="color: #000000; font-weight: bold;">var</span> myTarget:DisplayObject = getChildByName<span style="color: #66cc66;">&#40;</span>myTargetName<span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">dropTarget</span> <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&amp;&amp;</span> event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">dropTarget</span>.<span style="color: #006600;">parent</span> == myTarget<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    reply_txt.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Good Job!&quot;</span>;
<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
    reply_txt.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Try Again!&quot;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p class="image"><img src="http://www.monkeyflash.com/images/ddas306.gif" alt="Adding conditional logic to give a proper response." /></p>
<p class="caption">Adding conditional logic to give a proper response.</p>
<p>The first new line creates a text string from the word &#8220;target&#8221; plus the name of the peg we just dropped, creating a name that matches one of our targets, such as &#8220;<code>targetsquare_mc</code>&#8220;. The next line looks through our document for an object with that name, and saves a reference to it in a variable called &#8220;<code>myTarget</code>&#8220;. The <code>if</code> statement checks to make sure that the <code>dropTarget</code>, or the item that is under our shape when we release the mouse button, is not <code>null</code>, or empty. It also checks to see if the dropTarget&#8217;s parent is our <code>myTarget</code> . In other words, if we release <code>square_mc</code> over the movie clip named &#8220;<code>targetsquare_mc</code>&#8220;, we receive a positive reply. If the peg is released anywhere else, we will receive a negative reply.</p>
<p>Test the movie by pressing <strong>CTRL-Enter</strong>. Try clicking the square and dragging it over an incorrect hole in the toy. Now, try dropping it over the correct hole. Check your code and fix any errors you encounter.</p>
<h4>6. Use similar ActionScript to activate the other three pegs.</h4>
<p>Copy the event listener lines from the Actions panel and paste them three more times. Change each reference of <code>square_mc</code> to <code>flower_mc</code>, <code>triangle_mc</code>, and <code>pentagon_mc</code>, respectively. Do the same for the <code>buttonMode</code> line for each of the pegs. Since the event handler functions use references to <code>event.target</code>, there is no need to modify any other sections for it to work with all four pegs.</p>
<p class="image"><img src="http://www.monkeyflash.com/images/ddas307.gif" alt="Copying and pasting the event listeners for the other three pegs." /></p>
<p class="caption">Copying and pasting the event listeners for the other three pegs.</p>
<p>Press <strong>CRTL-Enter</strong> to test the movie. Try dragging each of the pegs into both incorrect and correct places on the toy. You should receive the correct messages each time.</p>
<h3>Bring the selected peg to the top</h3>
<p>Currently, if you drag the yellow triangle, it passes over the square, but underneath the pentagon and flower shapes. That&#8217;s because they were added to the Flash document in a specific order, and the newest objects end up on top in the stacking order. ActionScript 3.0 no longer uses depths when placing objects, as the <code>z-index</code> is handled automatically. In order to change the item&#8217;s z-index, we&#8217;ll use the <code>addChild()</code> method.</p>
<h4>7. Use addChild() to increase the peg&#8217;s stackin order</h4>
<p>We want to set the peg&#8217;s depth higher each time we drag it so that it will drag above the others. Add the following code within the <code>pickUp()</code> event handler, after the line <code>reply_txt.text = "";</code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">parent</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>In this line of code, <code>event.target.parent</code> refers to the main timeline. Using <code>addChild(event.target)</code> essentially adds the currently selected peg to the stage at the top of the stacking order, creating the appearance that we&#8217;ve picked it up above the others. Press <strong>CTRL-Enter</strong> to test the movie. As you drag each piece, it should always remain on top of the others.</p>
<h3>Locking pegs that have been placed correctly</h3>
<p>Once the user has placed a peg in the right hole, it is a good idea to &#8220;lock&#8221; it into place so that they can&#8217;t accidentally move it again. We&#8217;ll also make sure that the peg is perfectly positioned when it is released.</p>
<h4>8. Remove the event listeners when a peg is correctly placed.</h4>
<p>Once a peg is placed, the easiest way to ensure that we can&#8217;t move it again is to remove the event listeners, and set <code>buttonMode</code> back to false to remove the hand cursor. Add the following code within the <code>dropIt()</code> event handler, within the <code>if</code> statement, immediately after the line, <code>reply_txt.text="Good Job!";</code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, pickUp<span style="color: #66cc66;">&#41;</span>;
event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, dropIt<span style="color: #66cc66;">&#41;</span>;
event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">false</span>;</pre></div></div>

<p class="image"><img src="http://www.monkeyflash.com/images/ddas308.gif" alt="Removing the event listeners and buttonMode." /></p>
<p class="caption">Removing the event listeners and buttonMode.</p>
<p>When a peg is placed over the correct target, the <code>if</code> statement returns <code>true</code>, and that peg will be locked and no longer dragable. Test the movie with <strong>CTRL-Enter</strong> and see for yourself.</p>
<h4>9. Adjust the peg&#8217;s position when it is correctly placed</h4>
<p>We should also make sure that once a peg is placed, it fits perfectly over the target. Add the following code immediately under the code you just added:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">x</span> = myTarget.<span style="color: #006600;">x</span>;
event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">y</span> = myTarget.<span style="color: #006600;">y</span>;</pre></div></div>

<p>This will set the dropped peg&#8217;s <code>x</code> and <code>y</code> coordinates to match those of the target movie clip. Note that in ActionScript 3.0, <code>x</code> and <code>y</code> properties no longer have an underscore. Test the movie with <strong>CTRL-Enter</strong>.</p>
<h3>Resetting incorrectly placed pegs to their original position</h3>
<p>Currently, if you drag and drop a peg to either the wrong place or an empty area of the screen, it just stays there until you drag it again, which can be a little confusing. Let&#8217;s make each peg snap back to its original spot if it&#8217;s placed incorrectly.</p>
<h4>10. When clicked, record the peg&#8217;s starting position</h4>
<p>Since we&#8217;ll need this information within two event handlers, let&#8217;s set up a pair of variables. Add the following code to above all the rest in the Actions panel:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> startX:<span style="color: #0066CC;">Number</span>;
<span style="color: #000000; font-weight: bold;">var</span> startY:<span style="color: #0066CC;">Number</span>;</pre></div></div>

<p>This creates two variables, <code>startX</code> and <code>startY</code>, that will contain our starting position. For now, they&#8217;re empty. When we pick up the shape, we&#8217;ll record its coordinates. Add this next code within the <code>pickUp()</code> event handler:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">startX = event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">x</span>;
startY = event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">y</span>;</pre></div></div>

<h4>11. If the peg is released outside of its target, reset its x and y position</h4>
<p>Now that the starting position is recorded, we can use those values to reset the peg when we miss the target. Add the following code within the <code>dropIt()</code> handler, within the else statement:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">x</span> = startX;
event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">y</span> = startY;</pre></div></div>

<p class="image"><img src="http://www.monkeyflash.com/images/ddas309.gif" alt="Recording and resetting the peg's starting position." /></p>
<p class="caption">Recording and resetting the peg&#8217;s starting position.</p>
<p>This will reset the <code>x</code> and <code>y</code> properties to their original values, but only when we release the shape outside of its target. Test your movie with <strong>CTRL-Enter</strong>, and drag the square to an incorrect space. It should snap back to its starting position.</p>
<h3>Using a counter to determine when the user is finished</h3>
<p>Let&#8217;s add a congratulatory message that tells the user that all pegs have been placed correctly. We&#8217;ll need to keep a count of each correct peg drop, and when the count reaches four, we&#8217;ll change the text message.</p>
<h4>12. Create a global counter variable</h4>
<p>Since the counter will keep track of all four pegs, we will create a variable in the actions layer. Add the following code above all of the other code in the actions panel:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> counter:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;</pre></div></div>

<h4>13. Increment the counter variable each time a peg is correctly placed</h4>
<p>We will add one to the counter variable each time we release a peg over the right target. Add the following line of code within the <code>dropIt()</code> event handler, within the if statement:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">counter++;</pre></div></div>

<p class="image"><img src="http://www.monkeyflash.com/images/ddas310.gif" alt="Adding the counter increment to the dropIt() event handler." /></p>
<p class="caption">Adding the counter increment to the dropIt() event handler.</p>
<p>This will add one to the value of the counter variable when the square peg is placed correctly.</p>
<h4>14. Check the counter and update the text when it reaches four</h4>
<p>Add the following code within the <code>dropIt()</code> event handler, making sure that it comes after the <code>else</code> statement:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>counter == <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    reply_txt.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Congrats, you're finished!&quot;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p class="image"><img src="http://www.monkeyflash.com/images/ddas311.gif" alt="Checking the counter variable, and congratulating the user." /></p>
<p class="caption">Checking the counter variable, and congratulating the user.</p>
<p>This checks the <code>counter</code> variable&#8217;s value, and if it equals 4, it will change the text in the dynamic text field to read, &#8220;Congrats, you&#8217;re finished!&#8221;.</p>
<p id="preview">If you have JavaScript enabled, you will see the completed project here.</p>
<p><script type='text/javascript' src='/swf/swfobject.js'></script><br />
<script type='text/javascript'>
var s1 = new SWFObject('/swf/dragdrop_complete.swf','player','550','300','9');
s1.addParam('allowscriptaccess','always');
s1.write('preview');
</script></p>
<p>Here&#8217;s a look at the completed code.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> counter:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;
<span style="color: #000000; font-weight: bold;">var</span> startX:<span style="color: #0066CC;">Number</span>;
<span style="color: #000000; font-weight: bold;">var</span> startY:<span style="color: #0066CC;">Number</span>;
&nbsp;
square_mc.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, pickUp<span style="color: #66cc66;">&#41;</span>;
square_mc.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, dropIt<span style="color: #66cc66;">&#41;</span>;
triangle_mc.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, pickUp<span style="color: #66cc66;">&#41;</span>;
triangle_mc.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, dropIt<span style="color: #66cc66;">&#41;</span>;
flower_mc.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, pickUp<span style="color: #66cc66;">&#41;</span>;
flower_mc.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, dropIt<span style="color: #66cc66;">&#41;</span>;
pentagon_mc.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, pickUp<span style="color: #66cc66;">&#41;</span>;
pentagon_mc.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, dropIt<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> pickUp<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    event.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">startDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
    reply_txt.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
    event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">parent</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
    startX = event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">x</span>;
    startY = event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">y</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> dropIt<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    event.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">stopDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000000; font-weight: bold;">var</span> myTargetName:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;target&quot;</span> + event.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">name</span>;
    <span style="color: #000000; font-weight: bold;">var</span> myTarget:DisplayObject = getChildByName<span style="color: #66cc66;">&#40;</span>myTargetName<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">dropTarget</span> <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&amp;&amp;</span> event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">dropTarget</span>.<span style="color: #006600;">parent</span> == myTarget<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
        reply_txt.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Good Job!&quot;</span>;
        event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, pickUp<span style="color: #66cc66;">&#41;</span>;
        event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, dropIt<span style="color: #66cc66;">&#41;</span>;
        event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">false</span>;
        event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">x</span> = myTarget.<span style="color: #006600;">x</span>;
        event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">y</span> = myTarget.<span style="color: #006600;">y</span>;
        counter++;
    <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
        reply_txt.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Try Again!&quot;</span>;
        event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">x</span> = startX;
        event.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">y</span> = startY;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>counter == <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
        reply_txt.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Congrats, you're finished!&quot;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
square_mc.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">true</span>;
flower_mc.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">true</span>;
triangle_mc.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">true</span>;
pentagon_mc.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">true</span>;</pre></div></div>

<p class="flasource"><a href="/files/dragdrop.zip">Download the source FLA.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://monkeyflash.com/tutorials/flash-drag-and-drop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Index your site using VSpider</title>
		<link>http://monkeyflash.com/tutorials/using-vspider/</link>
		<comments>http://monkeyflash.com/tutorials/using-vspider/#comments</comments>
		<pubDate>Sun, 05 Nov 2006 20:09:44 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.monkeyflash.com/?p=77</guid>
		<description><![CDATA[Recently I needed to use Verity&#8217;s Spider (Vspider) to crawl my dynamic website to create a collection that could then be searched.  I was able to find useful information here and there but not just one place that had all the answers.  I&#8217;m not going to pretend to have all the answers, but [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I needed to use Verity&#8217;s Spider (Vspider) to crawl my dynamic website to create a collection that could then be searched.  I was able to find useful information here and there but not just one place that had all the answers.  I&#8217;m not going to pretend to have all the answers, but hopefully you will find this beginning-to-end tutorial of making a dynamic site searchable using Vspider helpful.</p>
<p>The last several versions of ColdFusion have shipped with a 3rd-party indexing engine called Verity.  Creating standard Verity collections is covered in most ColdFusion books in great detail.  The standard indexing is great if you have static .html or .cfm pages but what if you have pages that are mostly database driven?<span id="more-77"></span></p>
<p>That&#8217;s where Vspider comes in.  Vspider is a crawling tool that will go out on your website and index your dynamic pages.  It&#8217;s not perfect, but it does come free with ColdFusion for local site use.  Similar products can cost thousands of dollars, so Vspider is worth a look.</p>
<h3>Let&#8217;s build an example</h3>
<p><strong>Step 1</strong> &#8211; To use Vspider locally your site needs to resolve using the localhost domain.  To test this, just open a browser on your server and type in <code>http://localhost/</code>.  If your home page shows up then you are good to go.  If it doesn&#8217;t you will need to change your IIS settings to point the localhost domain to your site.  It is also fine for your home page to be in a subdirectory like <code>http://localhost/mysite/</code>.</p>
<p><strong>Step 2</strong> &#8211; Choose a directory on your server to store a text file that you will call from the command prompt.  I choose the <code>verity</code> directory under my CF installation directory.</p>
<p>Next create a text document using Notepad to contain all of your command calls.  Using a text document is much easier that typing the same thing over and over into the command prompt.</p>
<p>You can reference the <a href="http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&amp;file=00001778.htm">Adobe livedocs</a> for all of the Vspider commands but your document should look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">-style c:\cfusionmx\verity\data\stylesets\coldfusionvspider\
-collection c:\cfusionmx\verity\collections\newsite
-exclude http://localhost/newsite/_mmServerScripts/*
-exclude http://localhost/newsite/_notes/*
-exclude http://localhost/newsite/admin/*
-start http://localhost/newsite/index.cfm
-cgiok</pre></div></div>

<p>I saved this text file at <strong>myindex.txt</strong>.</p>
<p><strong>Step 3</strong> &#8211; Once the file is created you are ready to index your pages.  First open a command prompt window by selecting <strong>Start -&gt; Run</strong>, enter <code>cmd</code>, and click <strong>Run</strong>.  I normally change my directory to the c: directory by entering <code>cd C:\</code>.  Next you use the <code>cmdfile</code> command to call the Vspider command file that we created earlier.  The call looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">vspider -cmdfile c:\cfusionmx\verity\myindex.txt</pre></div></div>

<p class="image"><img src="/images/verity3.gif" alt="Code entered into Notepad and Command Prompt." /></p>
<p class="caption">Text file and Command Prompt code.</p>
<p><strong>Step 4</strong> &#8211; Open CF administrator and browse to the <strong>Verity Collections</strong> section.  Create a collection by filling out the form under <strong>Add New Verity Collections</strong>.  The name of your collection should be the same as the collection you created during indexing.  For this example it is <code>newsite</code>.  Choose the Language setting <strong>Englishx</strong> as your language because this is the language that Vspider uses.  Under <strong>Path</strong> you will want to enter the directory location where your collection was stored during indexing.  For this example it is <code>c:\cfusionmx\verity\collections</code>.</p>
<p class="image"><img src="/images/verity4.gif" alt="Verity Collections panel under CF Administrator." /></p>
<p class="caption">Settings as they appear in CF Administrator.</p>
<p><strong>Step 5</strong> &#8211; Once you&#8217;ve entered the collection into CF Administrator you should see the collection in the list under Verity Collections.  The number of documents in the collection should match the number indexed by Vspider.  At this point the collection has been created and mapped and is ready for use.</p>
<p>Now it&#8217;s time to create a search form to test your collection.  The following form will do the trick.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;search_action.cfm&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;criteria&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">maxlength</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Search&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>Place this form in a CFM file and save it at <code>search.cfm</code>.</p>
<p>You&#8217;ll also need an action page to process your search form.  This page will include a <code>cfsearch</code> call and a <code>cfoutput</code> to display the results.</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;">cfsearch</span> collection<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;newsite&quot;</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;GetResults&quot;</span> criteria<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#Form.criteria#&quot;</span> suggestions<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> status<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;info&quot;</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;">cfset</span> count<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</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;">cfoutput</span> <span style="color: #0000FF;">query</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;GetResults&quot;</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;">cfoutput</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;">cfset</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;">cfsearch</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">dl</span> <span style="color: #0000FF;">class</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;searchresults&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!--- Remove the http://localhost from the URL ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">dt</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #0000FF;">#count#</span>. <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">a</span> <span style="color: #0000FF;">href</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#replace(URL,&quot;</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #0000FF;">#Title#</span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">a</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">dt</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">dd</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #0000FF;">#Context#</span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">dd</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">dl</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> count<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;count&quot;</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;">cfset</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>If this search page will reside under the same domain as your site then the above example should work just fine.  If not then you can replace <code>http://localhost</code> with your site domain.</p>
<p>Save the action page as <code>search_action.cfm</code> in the same directory as <code>search.cfm</code>. View <code>search.cfm</code> in a browser, and use the form to test your collection.</p>
<p>The trick for me in this process was learning that you must index your website using Vspider BEFORE you create the collection in CF Administrator.  If you create the collection in CF Administrator first, Vspider will return a list of errors during indexing, none of which explain the problem.</p>
<p><em>-Guest Article by Richard Baldwin</em></p>
]]></content:encoded>
			<wfw:commentRss>http://monkeyflash.com/tutorials/using-vspider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aligning List Bullet Images</title>
		<link>http://monkeyflash.com/tutorials/aligning-list-bullet-images/</link>
		<comments>http://monkeyflash.com/tutorials/aligning-list-bullet-images/#comments</comments>
		<pubDate>Tue, 10 Oct 2006 17:36:00 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://beta.monkeyflash.com/?p=55</guid>
		<description><![CDATA[Recently, I fought another browser inconsistency battle over the placement of image bullets to the left of an unordered list.  While Firefox places the bullets where I expect, Internet Explorer places them too high, moving them out of alignment with the text. IE also occasionally moves the text too close to the bullet, and [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I fought another browser inconsistency battle over the placement of image bullets to the left of an unordered list.  While Firefox places the bullets where I expect, Internet Explorer places them too high, moving them out of alignment with the text. IE also occasionally moves the text too close to the bullet, and refuses to move it no matter what styles I apply. It&#8217;s only a minor difference, but in some cases this misalignment can become disorienting to the user.<span id="more-55"></span></p>
<h3>What&#8217;s going on here?</h3>
<p>The inconsistency occurs because the browsers disagree over where to position the <code>list-style-image</code> attribute, which is used to create custom bullets within an unordered list. I tried several small solutions, such as adjusting the <code>line-height</code> of the text or adding additional margins and padding, but these either had no effect or created even more inconsistencies.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">ul <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#2a245b</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">1.4</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">list-style-image</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">star.gif</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p class="image"><img src="/images/bulletlist1.gif" alt="Bullet list as displayed in Firefox and IE." /></p>
<p class="caption">Firefox (left) displays the list as expected, but Internet Explorer causes the bullet image to shift up and to the right.</p>
<p>Eventually, I decided to find another way to create the same effect without using <code>list-style-image</code>, and I found a solution that worked.</p>
<h3>Let&#8217;s try something else</h3>
<p>Since the browsers don&#8217;t agree on the position of the bullets, either in their default form or as an image, I did away with them entirely by using <code>list-style-type:none;</code>. This leaves me with a bare list, so it&#8217;s time to replace the bullet some other way.</p>
<p>I decided to place a background image in each of the list items and add just enough padding on the left side to make room for the image. This way, I can precisely control the display of the bullet using <code>background-position</code> if necessary, and place the text consistently where I want by using just the right amount of <code>padding-left</code>. This method still produces a standards-based accessible list, while creating a consistent web page across all modern browsers.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">ul <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#2a245b</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">1.4</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">list-style-type</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
li <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">25px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #3333ff;">:<span style="color: #993333;">transparent</span> </span>url<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">star.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p class="image"><img src="/images/bulletlist2.gif" alt="New version as displayed in both browsers." /></p>
<p class="caption">Both browsers display this version almost identically.</p>
<h3>A different approach</h3>
<p>You will frequently run into similar scenarios when developing CSS-based layouts, and often the answer isn&#8217;t the addition of more elements and styles. You can usually solve little inconsistencies by finding a different method to create the same effect &#8211; one that all browsers will render correctly.</p>
]]></content:encoded>
			<wfw:commentRss>http://monkeyflash.com/tutorials/aligning-list-bullet-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Image Rollover Navbar</title>
		<link>http://monkeyflash.com/tutorials/css-image-rollover-navbar/</link>
		<comments>http://monkeyflash.com/tutorials/css-image-rollover-navbar/#comments</comments>
		<pubDate>Fri, 30 Jun 2006 17:31:11 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://beta.monkeyflash.com/?p=53</guid>
		<description><![CDATA[Wouldn&#8217;t it be really cool if there were a way to create an image rollover that doesn&#8217;t require preloading images or JavaScript? Wouldn&#8217;t it be great if you could create horizontal or vertical navigation using only a clean unordered list markup in your HTML? How about having both of them, together?
Let&#8217;s take a look at [...]]]></description>
			<content:encoded><![CDATA[<p>Wouldn&#8217;t it be really cool if there were a way to create an image rollover that doesn&#8217;t require preloading images or JavaScript? Wouldn&#8217;t it be great if you could create horizontal or vertical navigation using only a clean unordered list markup in your HTML? How about having both of them, together?</p>
<p>Let&#8217;s take a look at the HTML code we will use for this example. I wanted to keep the code as clean as possible, while making it possible to arrange the display of the items in a variety of ways.<span id="more-53"></span> Both the vertical and horizontal navigation will be based in this simple list.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;navlist&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Menu Item 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Menu Item 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Menu Item 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Menu Item 4<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div>

<h3>Creating Pure CSS Rollovers</h3>
<p>Using CSS, image rollovers can be created using only a single image that is loaded when the page is called, eliminating the need to preload images using JavaScript. To create this effect, you&#8217;ll need to create images that contain the two or three states of your rollover within the same file.</p>
<p><img src="/images/rolloverimages.gif" alt="Rollover images, each with three states." style="border:none;"/></p>
<p>Once the images are ready, they are loaded into a container element, in this case the <code>&lt;a&gt;</code> tag, as a background image and cropped using the <code>&lt;a&gt;</code> tag&#8217;s width and height. Then it&#8217;s simply a matter of using the <code>background-position</code> property to move the image within the container to simulate the image swap effect.<br />
<style type="text/css"><!--#navlist { font-family:Arial, Helvetica, sans-serif; font-size:1.1em; font-weight:bold; list-style:none; padding:10px 5px; background:url(/images/bk.gif) repeat-y; border:2px solid #4e6b94; width:155px; float:right; margin:0 0 0 10px;} #navlist a {display:block; width:135px; color:#fff; text-decoration:none; background:url("/images/tab.gif") no-repeat; padding:4px 10px 2px 10px; } #navlist a:hover { background-position:0 -29px; color: #1e5ebd; } #navlist a:active { background-position:0 -58px; color:#1e5ebd;} #navlist li {background-image:none;padding:0;} --></style>
<h3>Vertical Navigation</h3>
<ul id="navlist">
<li><a href="#navlist">Menu Item 1</a></li>
<li><a href="#navlist">Menu Item 2</a></li>
<li><a href="#navlist">Menu Item 3</a></li>
<li><a href="#navlist">Menu Item 4</a></li>
</ul>
<p>First, let&#8217;s take a look at the CSS used to create a vertical navigation menu from the list. It&#8217;s really a simple matter of converting the display of the <code>&lt;a&gt;</code> tags to <code>display:block;</code>, and providing them with the proper width and height to display a single &#8220;state&#8221; from our image. The <code>hover</code> and <code>active</code> pseudo-classes are then used to move the <code>background-position</code> to simulate the rollover effect, as seen to the right. Remember to also remove the bullets by using <code>list-style:none;</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#navlist</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #3333ff;">:Arial</span><span style="color: #00AA00;">,</span> Helvetica<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">.8em</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#navlist</span> a <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">135px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;images/tab.gif&quot;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">7px</span> <span style="color: #933;">10px</span> <span style="color: #933;">6px</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#navlist</span> a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">-29px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#1e5ebd</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#navlist</span> a<span style="color: #3333ff;">:active </span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">-58px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#1e5ebd</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h3>How About Horizontal Tabs?</h3>
<p>Using the same HTML, we can create a horizontal list with the appearance of tabs by using a different image, and adjusting the CSS.  Note that the only real differences in this from the vertical example are that instead of setting the <code>&lt;a&gt;</code> tags to block, we use <code>float:left;</code> to place them to the right of one another. Also, we use <code>display:inline;</code> on the <code>&lt;li&gt;</code> tags to get them to display horizontally, which has the added benefit of automatically removing the bullets. (See the earlier article, <a href="http://www.monkeyflash.com/archives/2006/06/20/simple-horizontal-navbar-list/">Simple Horizontal Navbar List</a>, for another example.)</p>
<p>Here is the CSS, adjusted for a horizontal display.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#navbar</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #3333ff;">:Arial</span><span style="color: #00AA00;">,</span> Helvetica<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">.8em</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">45px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#navbar</span> li <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#navbar</span> a <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">110px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;images/tab2.gif&quot;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span> <span style="color: #933;">10px</span> <span style="color: #933;">13px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">-10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#navbar</span> a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">-45px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#1e5ebd</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#navbar</span> a<span style="color: #3333ff;">:active </span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">-90px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#1e5ebd</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The result is the horizontal tabbed menu below:<br />
<style type="text/css"><!-- #navbar { font-family:Arial, Helvetica, sans-serif; font-size:1.2em; font-weight:bold; padding:10px 20px; background:url(/images/bk2.gif) repeat-x; height:45px; border:2px solid #4e6b94; width:476px; margin-left:0;} #navbar li { list-style:none; display:inline; } #navbar a { width:110px; color:#fff; text-decoration:none; background:transparent url("/images/tab2.gif") no-repeat; float:left; padding:10px 10px 9px; margin:0 -10px;} #navbar a:hover { background-position:0 -45px; color:#1e5ebd; } #navbar a:active { background-position:0 -90px; color:#1e5ebd;} #navbar li {background-image:none;padding:0;} --></style>
<ul id="navbar">
<li><a href="#navbar">Menu Item 1</a></li>
<li><a href="#navbar">Menu Item 2</a></li>
<li><a href="#navbar">Menu Item 3</a></li>
<li><a href="#navbar">Menu Item 4</a></li>
</ul>
<p><strong>Note:</strong> In the examples displayed on this page, I&#8217;ve also included background images in the parent <code>&lt;ul&gt;</code> lists and additional padding, solely for appearance and easier recognition of the edges of the rollovers. Depending on the appearance of your buttons, this method may or may not be desirable, but will not affect the technique described here. You can see the examples on their own by downloading the <a href="/files/rolloverdemo.zip">example files</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://monkeyflash.com/tutorials/css-image-rollover-navbar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Horizontal Navbar List</title>
		<link>http://monkeyflash.com/tutorials/simple-horizontal-navbar-list/</link>
		<comments>http://monkeyflash.com/tutorials/simple-horizontal-navbar-list/#comments</comments>
		<pubDate>Tue, 20 Jun 2006 17:25:16 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://beta.monkeyflash.com/?p=50</guid>
		<description><![CDATA[One of the simplest and most efficient forms of navigation for a website is the horizontal list of items, separated by the pipe (&#124;) symbol. Unfortunately, marking up a &#60;p&#62; tag with the pipe character in between links is messy and not very accessible. A more efficient method to solve this problem is to use [...]]]></description>
			<content:encoded><![CDATA[<p>One of the simplest and most efficient forms of navigation for a website is the horizontal list of items, separated by the pipe (|) symbol. Unfortunately, marking up a <code>&lt;p&gt;</code> tag with the pipe character in between links is messy and not very accessible. A more efficient method to solve this problem is to use an unordered list to markup the navigation links. We can then use CSS to style the vertical list horizontally and add the appropriate separators.<span id="more-50"></span></p>
<h3>Start with an HTML list</h3>
<p>There are many ways to accomplish the effect we&#8217;re going for here, and some result in even cleaner HTML than this example. There are many impressive list conversions at <a href="http://css.maxdesign.com.au/listamatic/">Listamatic</a> for a variety of needs. This example will create a centered, horizontal set of HTML links separated by a vertical bar.</p>
<p>Our HTML markup looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;navlist&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Home<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Products<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Store<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>About<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;last&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Contact Us<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div>

<p>Overall, a very clean markup that&#8217;s easy to update and maintain. Notice that this markup does not contain the pipe symbol &#8211; we&#8217;ll add the separator using CSS. Although there are differences of opinion about whether or not the pipe character should be part of the content, my main reason for leaving it out of the HTML is to prevent screen readers like <a href="http://www.freedomscientific.com/fs_products/software_jaws.asp">JAWS</a> from awkwardly announcing a &#8220;vertical bar&#8221; after each list item.</p>
<p>The HTML contains only one <code>id="navlist"</code>, so that we can apply styles to this list in particular. It also contains one <code>class="last"</code> that we will use later to eliminate the extra separator.</p>
<h3>Blend in some nice CSS</h3>
<p>To convert an unordered list to a horizontal menu requires only a few CSS rules. Let&#8217;s take a look:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#navlist</span> li <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">.9em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#009</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>We begin by adjusting each <code>&lt;li&gt;</code> to <code>display:inline</code>, which forces the list items to display horizontally and removes the bullet point from the front of each. After adding a little left and right side padding, we replicate the effect of a vertical bar by adding a 1px <code>border</code> to the right side of each list item.</p>
<p class="image"><img src="/images/navbar1.gif" alt="Navbar displayed horizontally" /></p>
<p class="caption">The navbar is horizontal, but it still has an extra right border.</p>
<p>At this point, we have a functional horizontal navbar, but it has an extra right border hanging off of the end. To remove this extra border, I simply created the <code>.last</code> class and assigned it a value of <code>border:none</code>. It&#8217;s my least favorite part of the technique because of the extra class markup in the HTML, but I think it&#8217;s the best option to ensure that the entire list can be centered.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#navlist</span> li<span style="color: #6666ff;">.last</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#navlist</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #3333ff;">:Verdana</span><span style="color: #00AA00;">,</span> Arial<span style="color: #00AA00;">,</span> Helvetica<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">.7em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#navlist</span> a <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#009</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#navlist</span> a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#39F</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">underline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The final CSS rules apply text formatting to the list, center the entire list, and ensure link and hover states behave in a suitable manner. These are completely adjustable for your particular needs. For instance, I would most likely choose a smaller font size if I were using this technique for a footer.</p>
<p class="image"><img src="/images/navbar2.gif" alt="The finished horizontal navbar." /></p>
<p class="caption">The finished horizontal navbar.</p>
<p>Our finished navbar behaves consistently across browsers and maintains a very high degree of accessibility, while providing an easy-to-use and visually pleasing navigation scheme.</p>
]]></content:encoded>
			<wfw:commentRss>http://monkeyflash.com/tutorials/simple-horizontal-navbar-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SMS and ColdFusion MX 7</title>
		<link>http://monkeyflash.com/tutorials/sms-and-coldfusion/</link>
		<comments>http://monkeyflash.com/tutorials/sms-and-coldfusion/#comments</comments>
		<pubDate>Mon, 20 Jun 2005 20:07:34 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.monkeyflash.com/?p=75</guid>
		<description><![CDATA[In a recent discussion about an upcoming project, the idea of &#8220;reaching beyond the browser&#8221; came up.  We wanted to provide students (our target audience) with an avenue to provide feedback in addition to the web.  After our meeting we had two questions to answer: What was the best way to provide interaction [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent discussion about an upcoming project, the idea of &#8220;reaching beyond the browser&#8221; came up.  We wanted to provide students (our target audience) with an avenue to provide feedback in addition to the web.  After our meeting we had two questions to answer: What was the best way to provide interaction to mobile devices, and what could we use in our current infrastructure that would allow us to talk to mobile devices?</p>
<p>The answers were SMS (Short Message Service) and ColdFusion MX 7.  Thanks to the awesome Macromedia MAX conference in November, I was aware that ColdFusion MX 7 was going to include a new Event Gateway that allowed a ColdFusion application to send and receive SMS messages.  My next step was to set up a sample application, so our team members could see how it would work.<span id="more-75"></span></p>
<p>I was able to find a good overview of how a CF application and a mobile device communicate using SMS here: </p>
<p><strong><a href="http://www.macromedia.com/software/coldfusion/event_gateways/">http://macromedia.com/software/coldfusion/event_gateways/</a></strong></p>
<p>What I couldn&#8217;t find was a good step-by-step CF SMS example, so I pieced together what I could find and created this one. In this tutorial we will set up a CF gateway and create a sample application that will receive SMS messages as votes for candidates and send a confirmation message to the voter.</p>
<p><strong>Step 1</strong> &#8211; Locate your <strong>sms-test.cfg</strong> file in your CF installation directory under gateway\config\.</p>
<p><strong>Step 2</strong> &#8211; Copy this file and save it in the same directory as <strong>vote.cfg</strong> or a name of your choosing.</p>
<p>If you open this file you will see all of the settings that your Gateway Instance will use to send and receive messages.  Since this is a test application, we will use the default settings that point the Gateway Instance to IP 127.0.0.1, port 7901, and phone number 5551212.    </p>
<p><strong>Step 3</strong> &#8211; Create a blank CFC called <strong>vote.cfc</strong> and save it under your web root in a folder of your choosing.  This will be the file that processes all incoming SMS messages.</p>
<p><strong>Step 4</strong> &#8211; Login to CF Administrator and make sure the SMS Test Server is running under Event Gateways and Settings.</p>
<p><strong>Step 5</strong> &#8211; Create a new Gateway Instances in the CF Administrator under Event Gateways and Gateway Instances.</p>
<blockquote style="margin-left: 25px;"><p><strong>Gateway ID:</strong> SMS Vote &#8211; 5551212<br />
<strong>Gateway Type:</strong> SMS Gateway<br />
<strong>CFC Path:</strong> <em>web root</em>\subfolder\vote.cfc<br />
<strong>Configuration File:</strong> <em>cf rootdir</em>\gateway\config\vote.cfg<br />
<strong>Startup Mode:</strong> Automatic</p></blockquote>
<p><strong>Step 6</strong> &#8211; Start the SMS Vote &#8211; 5551212 Gateway Instance and make sure it is the only SMS Instance running.</p>
<p><strong>Step 7</strong> &#8211; Now that your Gateway is up and running we will add our SMS processing code to our <strong>vote.cfc</strong>.</p>
<p>First, we create our component and define our only method with the name <strong>onIncomingMessage</strong>.  This is the method that the gateway will call whenever there is an incoming message.  The only argument supplied by the gateway is a structure called CFEvent that contains information about the incoming message.</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;">cfcomponent</span> displayname<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;SMS Voting Listener&quot;</span> <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Process SMS messages.&quot;</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;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;onIncomingMessage&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;no&quot;</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;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;CFEvent&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;struct&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;yes&quot;</span> <span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>Next we pull the incoming message and the sender&#8217;s phone number out of the structure.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--- Get message data and sender number---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> voterMessage<span style="color: #0000FF;">=</span>arguments.CFEvent.<span style="color: #0000FF;">data</span>.message <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> voterNumber<span style="color: #0000FF;">=</span>arguments.CFEvent.originatorID <span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>We will also need to create a return structure to pass back to the gateway.  The command value is set to submit which will send the return message, the gatewayid is set as the source address for the message, and the destination address is set as the voter&#8217;s phone number.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--- Set up return struct with needed arguments---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> retValue<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;">cfset</span> retValue.command<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;submit&quot;</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;">cfset</span> retValue.sourceAddress<span style="color: #0000FF;">=</span>arguments.CFEvent.gatewayid <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> retValue.destAddress<span style="color: #0000FF;">=</span>voterNumber <span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>Next we will use a switch statement to process the incoming message.  If the message is &#8220;Carrie&#8221; or &#8220;Bo&#8221; then we will insert the vote and voter&#8217;s phone number into our database.  We also set the return message that thanks our user for voting.  If the incoming message wasn&#8217;t a candidate&#8217;s name then we return a &#8220;Not a voting option&#8221; message.</p>
<p>Note: Be sure to create a database and datasource (called &#8220;SMSVotes&#8221; in this example) for this code to use.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--- Add vote to db if incoming msg is a name and set return msg ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfswitch</span> expression<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#voterMessage#&quot;</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;">cfcase</span> <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Carrie&quot;</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;">cfquery</span> <span style="color: #0000FF;">datasource</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;SMSVotes&quot;</span><span style="color: #0000FF;">&gt;</span></span>
            INSERT INTO Votes(Phone, Vote)
            VALUES ('<span style="color: #0000FF;">#voterNumber#</span>', 'Carrie')
        <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfquery</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;">cfset</span> retValue.shortMessage<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Thank you for voting for &quot;</span> <span style="color: #0000FF;">&amp;</span> voterMessage <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfcase</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;">cfcase</span> <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Bo&quot;</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;">cfquery</span> <span style="color: #0000FF;">datasource</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;SMSVotes&quot;</span><span style="color: #0000FF;">&gt;</span></span>
            INSERT INTO Votes(Phone, Vote)
            VALUES ('<span style="color: #0000FF;">#voterNumber#</span>', 'Bo')
        <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfquery</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;">cfset</span> retValue.shortMessage<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Thank you for voting for &quot;</span> <span style="color: #0000FF;">&amp;</span> voterMessage <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfcase</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;">cfdefaultcase</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;">cfset</span> retValue.shortMessage<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Not a voting option: &quot;</span> <span style="color: #0000FF;">&amp;</span> voterMessage <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfdefaultcase</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;">cfswitch</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Lastly, we return our return structure with all the information the gateway needs to send our voter a confirmation message.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--- Send the return struct to gateway ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> retValue <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</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;">cfcomponent</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p><strong>Step 8</strong> &#8211; Now we need to test our application and to do this we will use a cell phone emulator that is installed with CF 7.  Go to Start -> Programs -> Macromedia -> ColdFusion MX 7 -> SMS Client Application.  This will launch a command prompt window along with a Java popup that is pre-filled with default connection information, which we will use.</p>
<p>Once you connect, you will see a simulated cell phone interface useful for testing purposes.  You can type your message by using the keypad on the cell phone or by selecting the text box and typing with your keyboard.  Try voting for Carrie, Bo, and a non-candidate to see if your application is working properly.  </p>
<p>That&#8217;s it!  That is all you need to do to get an example SMS application up and running.  As laid out in the Macromedia link above, you will need to set up an account with a SMSC (Short Message Service Center) such as AT&#038;T, Verizon, or Sprint to actually be able to send and receive SMS messages.  This provider will receive all the incoming SMS messages over their mobile network and then forward that message over TCP/IP to your ColdFusion server. After the SMSC provides you with settings for your <strong>vote.cfg</strong> file, you will be SMS enabled.  </p>
<p>I hope you found this tutorial useful. Now go forth and start texting!</p>
<p><em>-Guest Article by Richard Baldwin</em></p>
]]></content:encoded>
			<wfw:commentRss>http://monkeyflash.com/tutorials/sms-and-coldfusion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
