<?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>Carlo Alducente&#039;s Blog &#187; Forms</title>
	<atom:link href="http://labs.alducente.com/tag/forms/feed/" rel="self" type="application/rss+xml" />
	<link>http://labs.alducente.com</link>
	<description></description>
	<lastBuildDate>Thu, 12 Nov 2009 01:04:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Flash forms and how to make them less annoying to make</title>
		<link>http://labs.alducente.com/2008/11/21/flash-forms-and-how-to-make-them-less-annoying-to-make/</link>
		<comments>http://labs.alducente.com/2008/11/21/flash-forms-and-how-to-make-them-less-annoying-to-make/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 20:26:27 +0000</pubDate>
		<dc:creator>alducente</dc:creator>
				<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Forms]]></category>

		<guid isPermaLink="false">http://labs.alducente.com/?p=52</guid>
		<description><![CDATA[I&#8217;ve never been a big fan of creating forms in flash, like many others I would rather build an html form and let the backend guys deal with all the validating. But sometime it&#8217;s just unavoidable, specially when your entire site is in flash, popping open an html form is kinda dinky and not very [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve never been a big fan of creating forms in flash, like many others I would rather build an html form and let the backend guys deal with all the validating. But sometime it&#8217;s just unavoidable, specially when your entire site is in flash, popping open an html form is kinda dinky and not very good for consistency.</p>
<p>Here&#8217;s a couple things that I found made my life easier when creating forms in flash.</p>
<p><strong>Email Validation<br />
</strong>Here&#8217;s a good function that I snatched from a <a href="http://www.senocular.com/" target="_blank" onclick="urchinTracker('/outgoing/www.senocular.com/?referer=');">senocular</a> forum thread. Using AS3 regular expressions, it returns true if an email is valid and false if it&#8217;s not:</p>
<pre>function isValidEmail(email:String):Boolean {
	var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
	return emailExpression.test(email);
}</pre>
<p>All you have to do is pass the email in the parameter like so:</p>
<pre>trace(isValidEmail("carlo@alducente.com")) //traces "true"
trace(isValidEmail("woot!")) //traces "false"</pre>
<p><strong>Checking For Empty Fields<br />
</strong>This isn&#8217;t a big issue but found that it&#8217;s good to keep reminding myself that if text in a field is ==&#8221;" or == null, it doesn&#8217;t necessarily mean that it&#8217;s not empty.</p>
<p>Previously, in order to check for empty fields, i would always just check if the string is empty or equal to null, like so:</p>
<pre>if([string] == "" || [string] == null){
	//[string] is empty, throw a big fat bolded error.
}</pre>
<p>I did this for quite a while until i realized that people can still put in spaces only and it will bypass my validation because technically, the string is not empty. It&#8217;s got one (or more) spaces in it only. So here&#8217;s a quick function that I hacked together:</p>
<pre>function isNotEmpty(info:String):Boolean{
	var noSpaces:Array = info.split(" ");
	var a:uint;
	for (a = 0; a &lt; noSpaces.length;a++ ){
		if (noSpaces[a] != ""){
			return true;
		}
	}
	return false;
}</pre>
<p>Using the split() method of a string, i seperate the string into an array wherever there is a space. So if I call the function on &#8220;Carlo is blogging&#8221;, i get an array back that looks like this: ["Carlo", "is", "blogging"]. I can then loop through the array and check if there are any empty (&#8220;&#8221;) values in the array. If the Array is full of empty values, then the string is empty (return false), but if it finds at least one real value, return true.</p>
<p><strong>And the best for last: TABBING!! AAAHHHHH!!!!<br />
</strong>I&#8217;m probably the worst at remembering the tabbing order of my forms in flash. Just when you think you&#8217;re done with a form, the QA guy hits the &#8220;TAB&#8221; button and BLAM! You&#8217;re selection goes from the &#8220;First Name&#8221; field to some random movieclip and puts you to shame with a thick ugly yellow border around that movieclip.</p>
<p>There are two ways you can specify the tabbing order. You can do it by selecting the object you want to add tabbing on to, and going to Window&gt;Other Panels&gt;Accessibility. A window will popup with a &#8220;Tab index&#8221; field. There you can put in a number depending on the order of the tabbing. So if you want to make a text field the first one in the tabbing order, you just put 1 in that field.</p>
<p>You can also specify tabbing order through code, in AS3 objects have a &#8220;tabIndex&#8221; property, you can do the same thing above and give it a numerical value.</p>
<p>The one &#8220;gotcha&#8221; I always encounter is having random movieclips be part of the tabbing, highlighting it with a yellow border. The simplest solution to this is disabling the tabbing for that  movieclip by using the &#8220;tabEnabled&#8221; property.</p>
<pre>
myMovieClip.tabEnabled = false; //keeps it out of the tab order.
</pre>
<p>Any buttons on stage will automatically get added to the tabbing order, even if it&#8217;s originally a movieclip and you set its &#8220;buttonMode&#8221; property to true, that&#8217;s how I usually get that yellow border.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.alducente.com/2008/11/21/flash-forms-and-how-to-make-them-less-annoying-to-make/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
