<?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>Words, punctuated &#187; ColdFusion Flash Forms</title>
	<atom:link href="http://probertson.com/articles/category/flex/coldfusion-flash-forms/feed/" rel="self" type="application/rss+xml" />
	<link>http://probertson.com</link>
	<description>Thoughts on web development, user-centered design, code, etc. by Paul Robertson</description>
	<lastBuildDate>Tue, 20 Jul 2010 21:29:46 +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>Loading a cfform SWF into another SWF</title>
		<link>http://probertson.com/articles/2007/03/06/loading-cfform-into-swf/</link>
		<comments>http://probertson.com/articles/2007/03/06/loading-cfform-into-swf/#comments</comments>
		<pubDate>Tue, 06 Mar 2007 17:27:30 +0000</pubDate>
		<dc:creator>Paul Robertson</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Articles by Paul]]></category>
		<category><![CDATA[ColdFusion Flash Forms]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://probertson.com/articles/2007/03/06/loading-cfform-into-swf/</guid>
		<description><![CDATA[I haven&#8217;t written about ColdFusion Flash Forms in a while (I&#8217;m a Flex user now that you no longer need a server to create the content). However, this morning I got an interesting question from &#8220;trifide&#8221; that I hadn&#8217;t considered before, so I&#8217;m making a brief return into cfform land:
There are many attempts to loading [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t written about ColdFusion Flash Forms in a while (I&#8217;m a Flex user now that you no longer need a server to create the content). However, this morning I got an <a href="/articles/2005/10/03/dynamic-cfinput-label-2/#comment-12470">interesting question</a> from &#8220;trifide&#8221; that I hadn&#8217;t considered before, so I&#8217;m making a brief return into cfform land:</p>
<blockquote><p>There are many attempts to loading external swf into cfform… But what about the contrary? Do you know a way to embed cfform into a flash movie? i.e. call a cfform in a movieclip without getURL and external pop-up ..</p>
</blockquote>
<p>I started writing a comment response, but naturally it was getting pretty long-winded so I decided it deserved its own posting.</p>
<p>When you use cfform in a coldfusion page, the server generates a SWF file, with its own URL. (I don&#8217;t know whether it actually writes it to the disk, or whether it just keeps it in it&#8217;s memory &#8212; but from the end-user perspective that doesn&#8217;t really matter.) More specifically, it generates a SWF, then sends the appropriate HTML to the browser including the URL of the SWF. From the browser&#8217;s perspective the SWF is a completely separate item at a different URL &#8212; the browser doesn&#8217;t know that the programmer wrote it all in a single document. You can see the generated SWF&#8217;s URL by looking at the HTML source code of the CFM page.</p>
<p>For example, consider the page at the following URL (an example accompanying an article by the folks at <a href="http://asfusion.com/">ASFusion</a>):</p>
<p><a href="http://www.asfusion.com/blog/examples/cfdj/">http://www.asfusion.com/blog/examples/cfdj/</a></p>
<p>If you view the source, you&#8217;ll see that the page includes some JavaScript that is used to write the appropriate object and embed tags into the browser page. Right in the middle of that you&#8217;ll see this line (today at least; the file name may change in the future, as explained below):</p>
<pre><code>document.write("   src='/blog/examples/cfdj/859792312.mxml.cfswf' ");</code></pre>
<p>That&#8217;s the line of JavaScript that&#8217;s writing the SWF&#8217;s generated URL into the page. So we know that there is a URL that the web server will recognize and, when a computer requests that URL, the server will return the appropriate SWF.</p>
<p>You can try it out if you&#8217;d like &#8212; try requesting the SWF&#8217;s URL directly (i.e. http://www.asfusion.com/blog/examples/cfdj/859792312.mxml.cfswf) and you&#8217;ll see the same SWF, without the HTML page wrapper.</p>
<p>So, knowing the URL of the generated SWF, you can use it in the same way you&#8217;d use any SWF. As I mentioned, you can type the URL in the browser to request it directly, or you could alternatively load it into another SWF using <code>MovieClip.loadMovie()</code> or any other MovieClip loading technique (e.g. the Loader class in ActionScript 3.0).</p>
<h2>Potential issues</h2>
<p>There are, of course, a couple of gotchas that you&#8217;ll want to keep in mind.</p>
<ol>
<li>
<p>First of all, notice that the generated SWF&#8217;s URL is really just a number with a couple of file extensions. The reason for that is because this generated URL represents a single version of your cfform SWF. If you change the source code of the cfform in such a way that it needs to recompile the SWF, then the server will generate a new SWF with a new URL.  So any time you change your cfform, the URL will change too (and, obviously, you&#8217;ll need to change the URL that&#8217;s called by the other SWF doing the loading).  The reason the URL changes is to prevent the browser from using the cached (old) SWF &#8212; with a new URL, the browser loads a new SWF.</p>
<p>An obvious workaround is to just make a copy of the generated SWF and put it at a permanent URL. Like I said, I&#8217;m not sure if ColdFusion actually writes the generated SWF to the server&#8217;s hard drive, or whether it just keeps it in memory. If it does write it to disk it should be easy to get a copy from the server. If not, you can just load the SWF directly in a browser and then choose &#8220;Save As&#8230;&#8221; (or whatever) from your browser to save a copy of the SWF locally. BUT, by using a single URL, you lose the automatic versioning that prevents the browser from caching the SWF. You can find one idea to work around that issue (i.e. to do your own SWF versioning) in my article &#8220;<a href="/articles/2005/02/14/flash-databases-urlvars-flashvars/">Using URL Variables and FlashVars</a>&#8221; (specifically the URL Variables part of the article).</p>
</li>
<li>Second (and this is a big one): From my rudimentary tests, it looks like any queries in the CF page that the cfform uses are not available when you load the SWF separate from the CFM page.  I&#8217;m not sure why &#8212; I&#8217;d have to look more at the generated MXML to try to figure it out &#8212; but my guess is that the SWF makes use of the URL of its container HTML page to figure out where to communicate to get its data (rather than having the CFM page&#8217;s URL hard-coded into the SWF). Depending on what you want to use the cfform for, that probably throws a big wrench into things.</li>
<li>If you&#8217;re actually using the cfform for its intended purpose &#8212; that is, as a form to submit data &#8212; you&#8217;re going to have some issues with loading it into another SWF. When you submit a cf flash form, it navigates away from the current URL to the cfform tag&#8217;s &#8220;target&#8221; URL (essentially using <code>LoadVars.send()</code>, so clicking that button on a cfform SWF loaded into another SWF would navigate away from the container SWF as well.</li>
</ol>
<p>Finally, I can&#8217;t help but mention that loading a cfform SWF into another SWF may be a case of over-complicating something that can be done better in other ways. The obvious alternative is to just use Flex directly to create the form SWF, then loading the Flex SWF into the other SWF. Naturally, that means you&#8217;ll need to learn Flex&#8230;but if you&#8217;ve used cf flash forms then you&#8217;re already well on your way into that territory &#8212; just write out the generated mxml and take a look at what it consists of; then change a few things in the cfform and see how that changes the generated mxml&#8230;and so on. Don&#8217;t get me wrong &#8212; I&#8217;m sure there are legitimate reasons for using cfform rather than Flex in this situation, and I obviously can&#8217;t predict all the use cases. But over the long run I think you&#8217;ll find it&#8217;s a lot easier, without any of the issues or side effects, to use Flex.</p>
]]></content:encoded>
			<wfw:commentRss>http://probertson.com/articles/2007/03/06/loading-cfform-into-swf/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dynamically change a cfinput field&#8217;s label (new and improved)</title>
		<link>http://probertson.com/articles/2005/10/03/dynamic-cfinput-label-2/</link>
		<comments>http://probertson.com/articles/2005/10/03/dynamic-cfinput-label-2/#comments</comments>
		<pubDate>Mon, 03 Oct 2005 16:29:59 +0000</pubDate>
		<dc:creator>Paul Robertson</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Articles by Paul]]></category>
		<category><![CDATA[ColdFusion Flash Forms]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://probertson.com/articles/2005/10/03/dynamic-cfinput-label-2/</guid>
		<description><![CDATA[In a previous article I demonstrated a workaround approach to dynamically changing the label of a cfinput field in a ColdFusion Flash Form. Thanks to some great feedback from Laura Arguello, I&#8217;ve now worked out some improvements to the solution, so that it doesn&#8217;t require a &#8220;fake&#8221; label as the previous approach did. So, here [...]]]></description>
			<content:encoded><![CDATA[<p>In a <a href="/articles/2005/09/30/dynamic-cfinput-label/">previous article</a> I demonstrated a workaround approach to dynamically changing the label of a cfinput field in a ColdFusion Flash Form. Thanks to some <a href="http://www.asfusion.com/blog/entry/bindings-to-the-rescue-changing-an-input">great feedback</a> from <a href="http://asfusion.com/">Laura Arguello</a>, I&#8217;ve now worked out some improvements to the solution, so that it doesn&#8217;t require a &#8220;fake&#8221; label as the previous approach did. So, here it is, the new and improved way of dynamically changing the label of a cfinput field. (If you read the previous article, the explanations are similar &#8212; the solution is just simpler.)</p>
<p> If you want to skip the explanation, here is the <a href="/resources/2005/10/03/dynamic_label_cfinput_2.cfm.txt">finished working code</a>.</p>
<p class="editornote">Note: this example is intentionally more complicated than it might need to be &#8212; in some cases, it is possible to accomplish the same results using only data binding and without needing any additional ActionScript. Laura&#8217;s post gives a great example of this. For these examples, I intentionally decided to make it a bit more complicated, because it also allows for more flexibility in the final result. I recommend looking at both the simpler and the more complex approaches, and deciding what meets your needs best.</p>
<p>To begin, in this example there is a combo box (<code>&lt;cfselect&gt;</code>) in the form, as well as a text input field with a label (<code>&lt;cfinput type=&quot;text&quot;&gt;</code>).  The selected item in the combo box determines the label that is assigned to the cfinput text field; to control this, we will write some ActionScript for the cfselect&#8217;s onchange event (but we&#8217;ll get to that later). So that I don&#8217;t have to keep repeating it in later code listings, this is the CF code for the combo box and the form. To make this example more real-world, I&#8217;ve put a number as the value in each &lt;option&gt; tag &#8212; the ActionScript code in the event handler will need to use this number to determine what value to set for the label. Also notice that I&#8217;ve given the form a name &#8212; this is critical to the solution.</p>
<pre><code>&lt;cfform name=&quot;paymentForm&quot; format=&quot;flash&quot;&gt;
&lt;cfformgroup type=&quot;horizontal&quot;&gt;
	&lt;cfselect name=&quot;payMethod&quot; label=&quot;Method:&quot; width=&quot;150&quot; onchange=&quot;#payMethod_onChange#&quot;&gt;
			&lt;option value=&quot;-1&quot;&gt;&lt;/option&gt;
			&lt;option value=&quot;10&quot;&gt;Department Account&lt;/option&gt;
			&lt;option value=&quot;11&quot;&gt;Purchase Order&lt;/option&gt;
			&lt;option value=&quot;12&quot;&gt;Check&lt;/option&gt;
			&lt;option value=&quot;13&quot;&gt;Credit Card&lt;/option&gt;
		&lt;/cfselect&gt;
&lt;/cfformgroup&gt;

&lt;!---
The cfinput text field will be added here.
---&gt;

&lt;/cfform&gt;</code></pre>
<p>I think much of the confusion about being able to change a cfinput text field&#8217;s label dynamically lies in the way you define the label on a cfinput text field (by setting the &#8220;label&#8221; attribute in the tag &#8212; very easy). Naturally that leads to the (incorrect) assumption that you can just access a &#8220;label&#8221; property of the text field in ActionScript to change that label. Therein lies the biggest complication with using ActionScript in CF Flash Forms. Remember, the tags you define, and their attributes, are all part of ColdFusion. However, this is really all just a wrapper for the real Flex engine that is under the hood. Once the ColdFusion code gets turned into Flex MXML, the ColdFusion code is gone and you need to use the Flex object model to access the properties of your form fields (<a href="/articles/2005/08/10/creating_dynamic_form_fields/">more on this subject</a>).</p>
<p>One of the places this gives us trouble is with the label of a cfinput field such as an ordinary text input field. In CF, you might define it something like this:</p>
<pre><code>&lt;cfinput name=&quot;payDetail&quot; label=&quot;PO Number:&quot; type=&quot;text&quot; width=&quot;85&quot; /&gt;</code></pre>
<p>We have a basic cfinput text field. Pretty straightforward. Under the hood, this cfinput field gets turned into the following MXML:</p>
<pre><code>&lt;mx:FormItem label="PO Number:"&gt;
	&lt;mx:TextInput id="payDetail" text="{remoteObject_paymentForm.getData.result.payDetail}" width="85" heightFlex="0"/&gt;
&lt;/mx:FormItem&gt;</code></pre>
<p>Notice the critical difference here: the single cfinput tag actually gets turned into two distinct MXML tags (which means they are two different  objects from the perspective of  accessing them using ActionScript). The name you give to the cfinput field (&#8220;payDetail&#8221;) is assigned as the id of the <code>&lt;mx:TextInput&gt;</code> control. This is useful so that we can set it&#8217;s value, for instance. However, notice that the label we assigned is actually part of the <code>&lt;mx:FormItem&gt;</code> tag that wraps the <code>&lt;mx:TextInput&gt;</code> control. That means that the label itself is not a property of the <code>mx:TextField</code>, and the <code>mx:TextField</code> control knows nothing about it. In addition, the <code>mx:FormItem</code> tag doesn&#8217;t have any id assigned to it. This is critical &#8212; the id attribute of the MXML tag is what you use in ActionScript to refer to that object, so an item with no id can&#8217;t be accessed with ActionScript. This means, of course, that you can&#8217;t change the label directly using ActionScript. Ugh.</p>
<h2>The new solution </h2>
<p>(If you&#8217;ve been following along, here is where things start to change from the previous approach.) </p>
<p> So there is no way to directly change the actual label using ActionScript. However, as Laura kindly pointed out, we can define a binding statement for the label attribute of the cfinput tag, and that binding will cause the label to dynamically change any time the value it&#8217;s bound to changes:</p>
<pre><code>&lt;cfinput name=&quot;payDetail&quot; label=&quot;{}&quot; type=&quot;text&quot; width=&quot;85&quot; /&gt;</code></pre>
<p>So we can get the text into the label dynamically using a binding statement; the only question is, what do we specify as object/property to &#8220;bind&#8221; our label to? It can&#8217;t just be any ActionScript or other code &#8212; it has to be an actual object or property of an object.</p>
<p>We need to have a form field whose content will control the label of our text input field. Since we probably don&#8217;t want to have some random control appearing in the form, our best option is to use a hidden form field (<code>cfinput type=&quot;hidden&quot;</code>). The hidden form field won&#8217;t actually serve a purpose in terms of the data that is submitted by the form &#8212; it will simply act as a container that the label attribute is bound to. When the user chooses an item from the combo box, we will use ActionScript to set the value of the hidden form field to whatever we want the label to show, and Flex&#8217;s data binding will automatically update the label to match. Here&#8217;s what the CF code looks like with those changes:</p>
<pre><code>&lt;cfinput type=&quot;hidden&quot; name=&quot;payDetailLbl&quot; value=&quot;&quot; /&gt;
&lt;cfinput name=&quot;payDetail&quot; label=&quot;{paymentForm.payDetailLbl}&quot; type=&quot;text&quot; width=&quot;85&quot; /&gt;</code></pre>
<p>If you haven&#8217;t worked with them before, Flex (and CF Flash Forms) binding statements are always surrounded by curly braces. The natural inclination might be to just use the name of the hidden form field (&#8220;payDetailLbl&#8221;) in the curly braces, but that doesn&#8217;t work. In fact what you need to do is use [form name-dot-hidden field name] (&#8220;paymentForm.payDetailLbl&#8221; in this case). The reason for this is because hidden form fields are not actually added to the MXML as Flex controls, as visible controls are. Rather, they are added as elements in the <code>mx:Model</code> tag (which is essentially a general data repository that ultimately contains a value for each form field, which is how they get submitted back to ColdFusion when you submit a CF Flash Form). Those <code>mx:Model</code> elements are given names, and can be accessed in your cfform&#8217;s ActionScript as child properties of the form, as we do here.</p>
<p>All that&#8217;s left to do now is  to write the ActionScript which will change the label when a new value is selected in the combo box (its onchange event). Just for looks, we&#8217;ll also make it so that when no payment method is selected in the combo box, the input field is hidden. That means it will be hidden by default, so we need to make a minor change to our text input field so that it  looks like this (the change is bolded):</p>
<pre><code>&lt;cfinput name=&quot;payDetail&quot; label=&quot;{paymentForm.payDetailLbl}&quot; type=&quot;text&quot; <strong>visible=&quot;false&quot;</strong> width=&quot;85&quot; /&gt;</code></pre>
<p>Finally, the ActionScript itself will be written like this (yes, I&#8217;m still using <code>cfsavecontent</code> until my server admin installs CF MX 7.1):</p>
<pre><code>&lt;cfsavecontent variable=&quot;payMethod_onChange&quot;&gt;
payDetail.visible = true;

switch (payMethod.selectedItem.data) {
	case &quot;10&quot;: /* Department acct */
		paymentForm.payDetailLbl = &quot;Account #:&quot;;
		payDetail.width = 85;
		break;
	case &quot;11&quot;: /* PO */
		paymentForm.payDetailLbl = &quot;PO Number:&quot;;
		payDetail.width = 100;
		break;
	case &quot;12&quot;: /* Check */
		paymentForm.payDetailLbl = &quot;Check #:&quot;;
		payDetail.width = 85;
		break;
	case &quot;13&quot;: /* Credit Card */
		paymentForm.payDetailLbl = &quot;Card #:&quot;;
		payDetail.width = 120;
		break;
	default: /* no selection */
		payDetail.visible = false;
		break;
}
&lt;/cfsavecontent&gt;</code></pre>
<p>The code checks the value of the selected <code>&lt;option&gt;</code> from our <code>&lt;cfselect&gt;</code> tag . In ActionScript you access this using the <code>selectedItem.data</code> property of the combo box (whose id comes from the cfselect&#8217;s name). So in this case the value of whichever item is selected in the combo box appears in the code as <code>payMethod.selectedItem.data</code>. The code does the following things:</p>
<ol>
<li>The most common case (with the text field visible) is set (payDetail.visible = true). Otherwise this line would need to be repeated for almost every one of the possible conditions.</li>
<li>The switch statement checks the selected item in the combo box. (<code>payMethod.selectedItem.data</code>).</li>
<li> Depending on the item that is selected, the width of the text field is adjusted (since credit card numbers are usually longer than check numbers) and  the hidden form field&#8217;s value is set  (<code>paymentForm.payDetailLbl = &quot;[some label]&quot;</code>). Setting the hidden form field causes the label to be changed, because the cfinput tag&#8217;s label attribute is bound to the hidden field&#8217;s value.</li>
</ol>
<p>A couple of other points to note: </p>
<ul>
<li>The &#8220;default&#8221; case (which in this case is triggered if no payment method is selected) hides the text field completely by setting its <code>visible</code> property to false.</li>
<li>For the &#8220;case&#8221; values in the switch statement, even though the values are numbers they are wrapped in quotation marks. This is because the <code>payMethod.selectedItem.data</code> value is a String, and the switch statement in ActionScript uses strict equality to make its comparison (meaning it checks both the value and the data type of the variable being compared).</li>
<li>If you try this out at this point, you&#8217;ll notice that the form is &#8220;jumpy&#8221; &#8212; every time the label of the text field changes, the position of the form fields shifts because the label&#8217;s width changes. To get around this, in the final code I padded the combo box&#8217;s label with spaces on the left hand side so that it is always wider than the text field&#8217;s label &#8212; so it&#8217;s width (which doesn&#8217;t change) determines the position of the form fields. </li>
</ul>
<p>That&#8217;s all there is to it. You can <a href="/resources/2005/10/03/dynamic_label_cfinput_2.cfm.txt">download the final code</a> if you want to try it out..</p>
]]></content:encoded>
			<wfw:commentRss>http://probertson.com/articles/2005/10/03/dynamic-cfinput-label-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Dynamically change a cfinput form field&#8217;s label (ColdFusion Flash Forms)</title>
		<link>http://probertson.com/articles/2005/09/30/dynamic-cfinput-label/</link>
		<comments>http://probertson.com/articles/2005/09/30/dynamic-cfinput-label/#comments</comments>
		<pubDate>Fri, 30 Sep 2005 17:16:24 +0000</pubDate>
		<dc:creator>Paul Robertson</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Articles by Paul]]></category>
		<category><![CDATA[ColdFusion Flash Forms]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://probertson.com/articles/2005/09/30/dynamic-cfinput-label/</guid>
		<description><![CDATA[Note: After I wrote this article, Laura Arguello offered some valuable feedback which led me to a similar but better solution. Since I learned something new, I wanted to pass it along, so this article is now superseded by (a better way to) dynamically change a cfinput field&#8217;s label.
I&#8217;ve seen a couple of entries in [...]]]></description>
			<content:encoded><![CDATA[<p class="editornote">Note: After I wrote this article, <a href="http://asfusion.com/">Laura Arguello</a> offered some <a href="http://www.asfusion.com/blog/entry/bindings-to-the-rescue-changing-an-input">valuable feedback</a> which led me to a similar but better solution. Since I learned something new, I wanted to pass it along, so this article is now superseded by <a href="/articles/2005/10/03/dynamic-cfinput-label-2/">(a better way to) dynamically change a cfinput field&#8217;s label</a>.</p>
<p>I&#8217;ve seen a couple of entries in my server logs for people trying to figure out how to dynamically change the label of a cfinput field in a ColdFusion Flash Form. This is something I ran into myself a few weeks back, so I thought I&#8217;d share what I learned. </p>
<p>Unfortunately, this seems like it should be really easy, but it&#8217;s actually impossible to do &#8220;for real&#8221; (at least as far as I&#8217;ve found). I did figure out a way to get the same result using a bit of a workaround. To demonstrate this idea, I&#8217;ve built a simple CF Flash Form that has a combo box (<code>cfselect</code>) that lets you choose a payment method. Depending on your choice, the label of a <code>cfinput type=&quot;text&quot;</code> field changes. If you want to skip the explanation, here is the <a href="/resources/2005/09/30/dynamic_label_cfinput.cfm.txt">finished working code</a>. If you want to know more of the how and why, here goes: </p>
<p>Before I start, in this example there is a combo box (<code>&lt;cfselect&gt;</code>) in the form, as well as a text input field with a label (<code>&lt;cfinput type=&quot;text&quot;&gt;</code>).  The selected item in the combo box determines the label that is assigned to the cfinput text field; to control this, we will write some ActionScript for the cfselect&#8217;s onchange event (but we&#8217;ll get to that later). So that I don&#8217;t have to keep repeating it in later code listings, this is the CF code for the combo box and the form. Notice that to keep this example simple I&#8217;ve just put the desired label in as the value in each &lt;option&gt; tag. Obviously in a real-world scenario that will probably be some sort of number or database key. Also notice that I&#8217;ve given the form a name &#8212; this is critical to the solution.</p>
<pre><code>&lt;cfform name=&quot;paymentForm&quot; format=&quot;flash&quot;&gt;
&lt;cfformgroup type=&quot;horizontal&quot;&gt;
	&lt;cfselect name=&quot;payMethod&quot; width=&quot;150&quot; onchange=&quot;#payMethod_onChange#&quot;&gt;
			&lt;option&gt;&lt;/option&gt;
			&lt;option value=&quot;Account #&quot;&gt;Department Account&lt;/option&gt;
			&lt;option value=&quot;PO Number&quot;&gt;Purchase Order&lt;/option&gt;
			&lt;option value=&quot;Check #&quot;&gt;Check&lt;/option&gt;
			&lt;option value=&quot;Card #&quot;&gt;Credit Card&lt;/option&gt;
		&lt;/cfselect&gt;
&lt;/cfformgroup&gt;

&lt;!---
The cfinput text field will be added here.
---&gt;

&lt;/cfform&gt;</code></pre>
<p>I think much of the confusion about being able to change a cfinput text field&#8217;s label dynamically lies in the way you define the label on a cfinput text field (by setting the &#8220;label&#8221; attribute in the tag &#8212; very easy). Naturally that leads to the (incorrect) assumption that you can just access a &#8220;label&#8221; property of the text field in ActionScript to change that label. Therein lies the biggest complication with using ActionScript in CF Flash Forms. Remember, the tags you define, and their attributes, are all part of ColdFusion. However, this is really all just a wrapper for the real Flex engine that is under the hood. Once the ColdFusion code gets turned into Flex MXML, the ColdFusion code is gone and you need to use the Flex object model to access the properties of your form fields (<a href="/articles/2005/08/10/creating_dynamic_form_fields/">more on this subject</a>).</p>
<p>One of the places this gives us trouble is with the label of a cfinput field such as an ordinary text input field. In CF, you might define it something like this:</p>
<pre><code>&lt;cfinput name=&quot;payDetail&quot; label=&quot;PO Number:&quot; type=&quot;text&quot; width=&quot;85&quot; /&gt;</code></pre>
<p>We have a basic cfinput text field. Pretty straightforward. Under the hood, this cfinput field gets turned into the following MXML:</p>
<pre><code>&lt;mx:FormItem label="PO Number:"&gt;
	&lt;mx:TextInput id="payDetail" text="{remoteObject_paymentForm.getData.result.payDetail}" width="85" heightFlex="0"/&gt;
&lt;/mx:FormItem&gt;</code></pre>
<p>Notice the critical difference here: the single cfinput tag actually gets turned into two distinct MXML tags (which means they are two different  objects from the perspective of  accessing them using ActionScript). The name you give to the cfinput field (&#8220;payDetail&#8221;) is assigned as the id of the <code>&lt;mx:TextInput&gt;</code> control. This is useful so that we can set it&#8217;s value, for instance. However, notice that the label we assigned is actually part of the <code>&lt;mx:FormItem&gt;</code> tag that wraps the <code>&lt;mx:TextInput&gt;</code> control. That means that the label itself is not a property of the <code>mx:TextField</code>, and the <code>mx:TextField</code> control knows nothing about it. In addition, the <code>mx:FormItem</code> tag doesn&#8217;t have any id assigned to it. This is critical &#8212; the id attribute of the MXML tag is what you use in ActionScript to refer to that object, so an item with no id can&#8217;t be accessed with ActionScript. This means, of course, that you can&#8217;t change the label using ActionScript. Ugh.</p>
<p> So there is no way to change the actual label using ActionScript. There is there an alternative, a way we can simulate a label in a way which will allow it to be changed. One way to add arbitrary text to a CF Flash Form is using a <code>&lt;cfformitem type=&quot;text&quot;&gt;</code> element. So rather than using the built-in label for our form field, we can add a text formitem and use it as our field label. In order to get them to display like the form field&#8217;s label did, wrap them both in a <code>cfformgroup type=&quot;horizontal&quot;</code>:</p>
<pre><code>&lt;cfformgroup type=&quot;horizontal&quot;&gt;
 	&lt;cfformitem type=&quot;text&quot; width=&quot;75&quot;&gt;PO Number:&lt;/cfformitem&gt;
 	&lt;cfinput name=&quot;payDetail&quot; type=&quot;text&quot; width=&quot;85&quot; /&gt;
&lt;/cfformgroup&gt;</code></pre>
<p>In order to make it match the look of the real form field label, you will need to add some style attributes to the cfformitem element, but I left that out of this example for simplicity (the final code does contain styles). This ColdFusion code gets turned into the following MXML:</p>
<pre><code>&lt;mx:FormItem direction="horizontal" creationPolicy="all" widthFlex="1" heightFlex="1"&gt;
	&lt;mx:Text width="75" heightFlex="1"&gt;
		&lt;mx:text&gt;{remoteObject_paymentForm.getData.result.CFFORMITEM_4}&lt;/mx:text&gt;
	&lt;/mx:Text&gt;
	&lt;mx:TextInput id="payDetail" text="{remoteObject_paymentForm.getData.result.payDetail}" width="85" heightFlex="0"/&gt;
&lt;/mx:FormItem&gt;</code></pre>
<p>Something interesting to note is that the label text that is specified in the ColdFusion (&#8220;PO Number:&#8221;) doesn&#8217;t actually appear in the MXML &#8212; instead it is represented by the Flex binding statement <code>{remoteObject_paymentForm.getData.result.CFFORMITEM_4}</code>. That&#8217;s very promising &#8212; it means that that text is actually being accessed dynamically, which means we can probably also change it. In fact we can. The <code>mx:Text</code> control that is created from our <code>cfformitem type=&quot;text&quot;</code> tag doesn&#8217;t have an id attribute, so we can&#8217;t access it directly using ActionScript, but one of the attributes we can use in the <code>cfformitem type=&quot;text&quot;</code> tag is the &#8220;bind&#8221; attribute, which allows us to specify an object property that will serve as the source of the text. So we&#8217;ll get the text into the label dynamically using a bind statement; the only question is, what do we specify as object/property to &#8220;bind&#8221; our label to? It can&#8217;t just be any ActionScript or other code &#8212; it has to be an actual object or property of an object.</p>
<p>Remember I warned you, this does require a bit of a workaround. We need to have a form field whose content will control the label of our text input field. Since we probably don&#8217;t want to have some random control appearing in the form, our best option is to use a hidden form field (<code>cfinput type=&quot;hidden&quot;</code>). The hidden form field won&#8217;t actually serve a purpose in terms of the data that is submitted by the form &#8212; it will simply act as a container that the label formitem is bound to. When the user chooses an item from the combo box, we will use ActionScript to set the value of the hidden form field to whatever we want the label to show, and Flex&#8217;s data binding will automatically update the label to match. Here&#8217;s what the CF code looks like with those changes:</p>
<pre><code>&lt;cfformgroup type=&quot;horizontal&quot;&gt;
	&lt;cfformitem type=&quot;text&quot; width=&quot;75&quot; <strong>bind=&quot;{paymentForm.payDetailLbl}&quot;</strong> /&gt;
	<strong>&lt;cfinput type=&quot;hidden&quot; name=&quot;payDetailLbl&quot; value=&quot;&quot; /&gt;</strong>
	&lt;cfinput name=&quot;payDetail&quot; type=&quot;text&quot; width=&quot;85&quot; /&gt;
&lt;/cfformgroup&gt;</code></pre>
<p>For me, one tricky part was figuring out the exact syntax to use in the &#8220;bind&#8221; statement to refer to the hidden form field&#8217;s value. If you haven&#8217;t worked with them before, Flex (and CF Flash Forms) binding statements are always surrounded by curly braces. First I tried using just the name of the hidden form field (&#8220;payDetailLbl&#8221;) but that didn&#8217;t work. After a bit I figured out that I needed to use [form name-dot-hidden field name] (&#8220;paymentForm.payDetailLbl&#8221; in this case). The reason for this is because hidden form fields are not actually added to the MXML as Flex controls, the same way visible controls are. Rather, they are added as elements in the <code>mx:Model</code> tag (which is essentially a general data repository that ultimately contains a value for each form field, which is how they get submitted back to ColdFusion when you submit a CF Flash Form). Those <code>mx:Model</code> elements are given names, and can be accessed in your cfform&#8217;s ActionScript as child properties of the form, as we do here.</p>
<p>We&#8217;re almost there now &#8212; all we have to do is make it work =). More specifically, we need to write the ActionScript which will change the label when a new value is selected in the combo box (its onchange event). Just for looks, we&#8217;ll also make it so that when no payment method is selected in the combo box, the input field is hidden. That means it will be hidden by default, so we need to make a minor change to our text input field so that it  looks like this (the change is bolded):</p>
<pre><code>&lt;cfinput name=&quot;payDetail&quot; <strong>visible=&quot;no&quot;</strong> type=&quot;text&quot; width=&quot;85&quot; /&gt;</code></pre>
<p>Finally, the ActionScript itself will be written like this (yes, I&#8217;m still using <code>cfsavecontent</code> until my server admin installs CF MX 7.1):</p>
<pre><code>&lt;cfsavecontent variable=&quot;payMethod_onChange&quot;&gt;
if (payMethod.selectedItem.data == &quot;&quot;) {
	payDetail.visible = false;
	paymentForm.payDetailLbl = &quot;&quot;;
} else {
	payDetail.visible = true;
	paymentForm.payDetailLbl = payMethod.selectedItem.data;
}
&lt;/cfsavecontent&gt;</code></pre>
<p>The code uses the value of the selected <code>&lt;option&gt;</code> from our <code>&lt;cfselect&gt;</code> tag . In ActionScript you access this using the <code>selectedItem.data</code> property of the combo box (whose id comes from the cfselect&#8217;s name). So in this case the value of whichever item is selected in the combo box appears in the code as <code>payMethod.selectedItem.data</code>. The code does the following things:</p>
<ol>
<li>The <code>if</code> statement checks if the default (blank) item was chosen.</li>
<li>If so, it hides the input field (<code>payDetail.visible = false</code>) and sets the label to <code>&quot;&quot;</code> (an empty string).</li>
<li> Otherwise, a real value is selected, so the input field is shown (<code>payDetail.visible = true</code>) and the hidden form field&#8217;s value is set (<code>paymentForm.payDetailLbl = payMethod.selectedItem.data</code>). Remember that setting the hidden form field causes the label to be changed, because it is bound to the hidden form field through the &#8220;bind&#8221; attribute.</li>
</ol>
<p>That&#8217;s all there is to it. You can <a href="/resources/2005/09/30/dynamic_label_cfinput.cfm.txt">download the final code</a> if you want to try it out, or to see how I added style formatting to the field to make it look like a real field label. One thing you may notice is that in the final code I added a label to the combo box as well. In order to make things line up nicely, it uses another fake label created with cfformitem type=&quot;text&quot;, even though in that case the label isn&#8217;t actually dynamic.</p>
]]></content:encoded>
			<wfw:commentRss>http://probertson.com/articles/2005/09/30/dynamic-cfinput-label/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Getting meaningful data from dynamically generated fields in ColdFusion Flash Forms</title>
		<link>http://probertson.com/articles/2005/08/10/getting_data_back/</link>
		<comments>http://probertson.com/articles/2005/08/10/getting_data_back/#comments</comments>
		<pubDate>Wed, 10 Aug 2005 21:36:25 +0000</pubDate>
		<dc:creator>Paul Robertson</dc:creator>
				<category><![CDATA[Articles by Paul]]></category>
		<category><![CDATA[ColdFusion Flash Forms]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://probertson.com/articles/2005/08/10/getting_data_back/</guid>
		<description><![CDATA[Part 4 of My first foray into ColdFusion Flash Forms.
Note: This article will make more sense if you read the previous one first.
In the previous articles I talked about two approaches to creating a repeating set of form controls (in this case checkboxes) in a ColdFusion Flash Form, based on data in a query. I [...]]]></description>
			<content:encoded><![CDATA[<p>Part 4 of <a href="../first_flash_forms/">My first foray into ColdFusion Flash Forms</a>.</p>
<p class="note">Note: This article will make more sense if you read <a href="../creating_dynamic_form_fields/">the previous one</a> first.</p>
<p>In the previous articles I talked about two approaches to creating a repeating set of form controls (in this case checkboxes) in a ColdFusion Flash Form, based on data in a query. I recommended one approach, which is to use a cfformgroup type=&quot;repeater&quot; tag to create multiple controls, because it doesn’t require the SWF file to be regenerated each time the underlying data changes. The alternative, using a cfloop tag to create cfinput type=&quot;checkbox&quot; controls, does require the SWF file to be regenerated each time the underlying data changes.</p>
<p>However, the cfloop approach has a big advantage. By creating the checkbox controls separately within your CFML, you can specify a separate name for each checkbox control, and it is easy to differentiate between them when the form is submitted.</p>
<p>Consider these two examples (which are the same as in the previous article, except that I have added a &#8220;submit&#8221; button to the form).</p>
<pre><code>&lt;cfform name=&quot;form1&quot; format=&quot;flash&quot; height=&quot;600&quot; width=&quot;450&quot;&gt;

	&lt;cfformgroup type=&quot;repeater&quot; query=&quot;q1&quot;&gt;
		&lt;cfinput type=&quot;Checkbox&quot; name=&quot;chk&quot; Label=&quot;{q1.currentItem.firstname + ' ' + q1.currentItem.lastname}&quot;&gt;
	&lt;/cfformgroup&gt;
	&lt;cfformgroup type=&quot;horizontal&quot;&gt;
		&lt;cfinput type=&quot;submit&quot; name=&quot;submitBtn&quot; value=&quot;Send Data&quot; width=&quot;100&quot;&gt;
	&lt;/cfformgroup&gt;
&lt;/cfform&gt;</code></pre>
<p>As described previously, this example uses a <code>cfformgroup type=&quot;repeater&quot;</code>, which dynamically generates the checkboxes on the client, using ActionScript in the SWF file.</p>
<pre><code>&lt;cfform name=&quot;form1&quot; format=&quot;flash&quot; height=&quot;400&quot; width=&quot;450&quot;&gt;
	&lt;cfformgroup type=&quot;VBox&quot;&gt;
		&lt;cfloop query=&quot;q1&quot;&gt;
			&lt;cfinput type=&quot;checkbox&quot; name=&quot;boxMBAa_#id#&quot; label=&quot;#firstname# #lastname#&quot;&gt;
		&lt;/cfloop&gt;
	&lt;/cfformgroup&gt;
	&lt;cfformgroup type=&quot;horizontal&quot;&gt;
		&lt;cfinput type=&quot;submit&quot; name=&quot;submitBtn&quot; value=&quot;Send Data&quot; width=&quot;100&quot;&gt;
	&lt;/cfformgroup&gt;
&lt;/cfform&gt;</code></pre>
<p>Again, the difference here is that a <code>cfloop</code> is used to generate the checkboxes in the server, so in the generated MXML (and the generated SWF file) they are separate checkbox controls.</p>
<p>When you submit these forms, the results are surprisingly different.</p>
<p>The output of the first example (using <code>cfdump var=&quot;#form#&quot;</code>) looks like this (assuming the first and the third checkboxes are checked):</p>
<p><img src="/resources/2005/08/10/result_1.png" width="198" height="98" alt="Results of the first form."></p>
<p>While the output of the second example looks like this:</p>
<p><img src="/resources/2005/08/10/result_2.png" width="448" height="157" alt="Results of the second form."></p>
<p>Obviously there is a significant difference. When we submit the first form, we only get one name/value pair containing the values for all the checkboxes. Not only that, but all we get for each checkbox is a true/false value. There is no practical way that we can figure out which associated value in our underlying data source was selected. However, with the second example, because each checkbox was created separately on the server (and we were able to give each one its own name) we see four different name/value pairs &#8212; one for each checkbox.</p>
<p>This is a serious problem for the <code>cfformgroup type=&quot;repeater&quot;</code> approach to dynamically creating form controls. If there isn&#8217;t any way to get the data back, there isn&#8217;t really any point to creating the form a in the first place. I hoped that there would be a way to assign a &#8220;data&#8221; value to each checkbox which would get returned in place of the true/false value (in the same way that multiple checkboxes with the same name in an HTML form return a value). But there doesn&#8217;t seem to be a way to do this.</p>
<p>Unfortunately, I think this boils down to a limitation in the fact that the CF Flash Forms are using Flex but are submitting their data as if they were HTML forms. If we were actually building this same form using Flex, then there would be no need to get anything more than a true/false value from the checkbox. If we wanted to know which underlying values were selected, within our Flex application we could write code that would loop through the checkboxes to find out which ones are checked, and use that in combination with the underlying data (which would also be available to the ActionScript) &#8212; we could then manipulate that data, send it to the server, etc. however we like.</p>
<p>But that isn&#8217;t how CF Flash Forms work &#8212; they submit their data to the server as though it was from a traditional web form. Note that we could actually use an alternative approach (e.g. Flash Remoting) to submit our data, rather than using the standard &#8220;submit&#8221; behavior of the Flash Form &#8212; but that seems like a lot of extra work just so that we can have a dynamically generated set of form controls built the right way according to Macromedia&#8217;s recommendations.</p>
<p>However, I was able to come up with a workaround. Admittedly the data submitted by the form isn&#8217;t necessarily as clean and convenient as with the &#8220;checkboxes generated by <code>cfloop</code>&#8221; approach, but it at least makes it possible to get the data associated with checkboxes.</p>
<p>The solution: <code>input type=&quot;hidden&quot;</code>. As you probably know, within an HTML form you can use a &#8220;hidden&#8221; form field to store a value which gets submitted by the browser but which doesn’t have any visible manifestation on the page. With a CF Flash Form, you can add an <code>input type=&quot;hidden&quot;</code> field to the form which has the same effect. So to get the id values associated with our checkboxes, we just need to create a hidden form field which contains all the id values in a comma separated list. Just add these lines to your code:</p>
<pre><code>.
.
.
&lt;cfparam name=&quot;mylist&quot; default=&quot;&quot;&gt;
&lt;cfloop query=&quot;q1&quot;&gt;
	&lt;cfset mylist = listappend(mylist,#q1.id#)&gt;
&lt;/cfloop&gt;
.
.
.
&lt;cfform name=&quot;form1&quot; format=&quot;flash&quot; height=&quot;600&quot; width=&quot;450&quot;&gt;
.
.
.
	&lt;!--- the code for the repeating form controls (i.e. the cfformgroup type=&quot;repeater&quot;) goes here ---&gt;
	&lt;cfinput type=&quot;hidden&quot; name=&quot;ids&quot; value=&quot;#mylist#&quot;&gt;
&lt;/cfform&gt;
.
.
.</code></pre>
<p>Notice that outside the <code>cfform</code> tag we use <code>cfloop</code> to create a variable that is a ColdFusion &#8220;list&#8221; containing all the id values from our query. The contents of that variable are then set as the value of our hidden form field.</p>
<p>So now when we submit our form, we see results that look like this:</p>
<p><img src="/resources/2005/08/10/result_3.png" width="213" height="117" alt="Results of the first form, with the addition of a hidden form field."></p>
<p>Notice the one (significant!) difference &#8212; there is now an extra name/value pair being submitted by our form, containing a comma-separated list of the ids from our query. Within the page that processes this form submission, we will have to loop through the two form fields (the one containing the true/false values and the other containing the ids) to match them up, in order to determine which values are the &#8220;selected&#8221; ones.</p>
<p>At this point, astute readers will probably be thinking &#8220;wait a minute, in the last article Paul said that it’s bad to use <code>cfloop</code> with CF Flash Forms, because the server has to regenerate the data each time the data changes. What gives?&#8221;</p>
<p>That was exactly my concern with using this approach. However, the CF engineers apparently anticipated this need (and here I have to give big kudos to those CF engineers, because I think what they&#8217;ve done is just brilliant). Take a look at the MXML generated when the <code>&lt;input type=&quot;hidden&quot; /&gt; </code> is included. Try to find what the <code>&lt;input type=&quot;hidden&quot; /&gt; </code> gets turned into in MXML. Give up? Look near the top for a tag named <code>mx:Model</code>. It looks like this:</p>
<pre><code>&lt;mx:Model id=&quot;form1&quot;&gt;
	&lt;chk&gt;{chk.selected}&lt;/chk&gt;
	&lt;ids&gt;{remoteObject_form1.getData.result.ids}&lt;/ids&gt;
&lt;/mx:Model&gt;</code></pre>
<p>Notice that it contains two elements, which correspond exactly to the values that are submitted with the form. The <code>&lt;chk&gt;</code> is how the true/false values actually get put into the form field named &#8220;chk&#8221; that is submitted with the form. And there&#8217;s our hidden form field, in the <code>&lt;ids&gt;</code> tag. Notice something very important about it: it doesn&#8217;t contain a hard-coded list of values which would need to be recompiled each time. Rather, it contains a binding to an ActionScript value (the stuff in curly brackets {}). At the end of the previous article I pointed out that the &#8220;remoteObject_form1&#8221; is an object defined in the Flex MXML that essentially is how the SWF file gets the latest data each time it is loaded in the browser, without needing to recompile on the server. The value contained in the <code>&lt;ids&gt;</code> tag is a binding to the &#8220;ids&#8221; property of that same remote object. This means that each time the SWF file loads and gets the latest data from the server, it also gets the latest values to submit as the ids form field &#8212; but still without requiring the server to recompile the MXML.</p>
<p>Again, all I can say is that whoever wrote the code that is smart enough to turn my ColdFusion code (that I just wrote off pretty much off the top of my head)&#8230;</p>
<pre><code>&lt;cfparam name=&quot;mylist&quot; default=&quot;&quot;&gt;
&lt;cfloop query=&quot;q1&quot;&gt;
	&lt;cfset mylist = listappend(mylist,#q1.id#)&gt;
&lt;/cfloop&gt;</code></pre>
<p>&#8230;into this MXML&#8230;</p>
<pre><code>&lt;mx:Model id=&quot;form1&quot;&gt;
.
.
.
&lt;ids&gt;{remoteObject_form1.getData.result.ids}&lt;/ids&gt;
&lt;/mx:Model&gt;</code></pre>
<p>&#8230;is just brilliant.</p>
<p>(Well, either that or I just got really really lucky and happened to type just the right CF code that gets turned into that MXML. Okay, we all know how likely that is. =)</p>
]]></content:encoded>
			<wfw:commentRss>http://probertson.com/articles/2005/08/10/getting_data_back/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Creating &#8220;dynamic&#8221; form fields in ColdFusion Flash Forms &#8212; how and why</title>
		<link>http://probertson.com/articles/2005/08/10/creating_dynamic_form_fields/</link>
		<comments>http://probertson.com/articles/2005/08/10/creating_dynamic_form_fields/#comments</comments>
		<pubDate>Wed, 10 Aug 2005 21:35:14 +0000</pubDate>
		<dc:creator>Paul Robertson</dc:creator>
				<category><![CDATA[Articles by Paul]]></category>
		<category><![CDATA[ColdFusion Flash Forms]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://probertson.com/articles/2005/08/10/creating_dynamic_form_fields/</guid>
		<description><![CDATA[Part 3 of My first foray into ColdFusion Flash Forms. 
If you are used to using ColdFusion (or any other web development language that outputs HTML) you are probably used to the conceptual notion that these pages are like &#8220;templates&#8221;:

You create a file containing static text (generally HTML code) mixed with programming code
The server works [...]]]></description>
			<content:encoded><![CDATA[<p>Part 3 of <a href="../first_flash_forms/">My first foray into ColdFusion Flash Forms</a>. </p>
<p>If you are used to using ColdFusion (or any other web development language that outputs HTML) you are probably used to the conceptual notion that these pages are like &#8220;templates&#8221;:</p>
<ol>
<li>You create a file containing static text (generally HTML code) mixed with programming code</li>
<li>The server works through the code, processes it all (resolves all variables, loops, etc. to fixed values), and generates text output (the HTML page)</li>
<li>The server sends that text output to the browser, which renders it.</li>
</ol>
<p>While the CF Flash Forms work in a similar way, the process has some differences which are important to understand in order to make your forms work the way you want them to:</p>
<ol>
<li>You create a file containing static text mixed with programming code.</li>
<li>For any code inside a CFFORM tag with type=&quot;flash&quot;, the steps change a bit:
<ol>
<li>The server works through the code, resolving all variables, loops, etc. to fixed values as though you had hard-coded them within your ColdFusion code.</li>
<li>The server converts the now static CF code within the CFFORM tag to Flex MXML.</li>
<li>The MXML code is sent to the Flex compiler, which generates a SWF file from it.</li>
</ol>
</li>
<li>Within the HTML page that the server sends to the browser, the server adds the appropriate tags to load the SWF file that is dynamically generated by the Flex compiler.</li>
</ol>
<p class="note">Note: this is just a conceptual explanation of the process, based on my experimentation. I have no idea whether this is actually how the process works, but this seems to be close enough to the reality to help me understand some important details about CF Flash Forms.</p>
<p>The critical part of this explanation is in point 2. Before the CFFORM content gets converted to Flex MXML (which will ultimately become the SWF file), all the variables, loops etc. &#8212; essentially, anything within a pair of # signs &#8212; gets resolved. The then-static CFML tags are converted to MXML. Why is this important? Compare the following examples.</p>
<p>These are two different ways of creating a dynamic list of checkbox controls in a CF Flash Form, based on data from a query (e.g. a database query). Both assume you have a query named q1 with three fields (id, firstname, lastname). In case you&#8217;re curious, these snippets are portions of the code presented in the previous article on <a href="../select_all_cf_flash_forms/">two ways to create a &#8220;select all&#8221; button for checkboxes in a CF Flash Form</a>.</p>
<pre><code>&lt;cfform name=&quot;form1&quot; format=&quot;flash&quot; height=&quot;600&quot; width=&quot;450&quot;&gt;
	&lt;cfformgroup type=&quot;repeater&quot; query=&quot;q1&quot;&gt;
		&lt;cfinput type=&quot;Checkbox&quot; name=&quot;chk&quot; Label=&quot;{q1.currentItem.firstname + ' ' + q1.currentItem.lastname}&quot;&gt;
	&lt;/cfformgroup&gt;
&lt;/cfform&gt;</code></pre>
<p>In order to create one checkbox instance per item in the query, this first example uses <code>cfformgroup type=&quot;repeater&quot;</code> with a single <code>cfinput type=&quot;checkbox&quot;</code> tag nested within it.</p>
<pre><code>&lt;cfform name=&quot;form1&quot; format=&quot;flash&quot; height=&quot;400&quot; width=&quot;450&quot;&gt;
	&lt;cfformgroup type=&quot;VBox&quot;&gt;
		&lt;cfloop query=&quot;q1&quot;&gt;
			&lt;cfinput type=&quot;checkbox&quot; name=&quot;boxMBAa_#id#&quot; label=&quot;#firstname# #lastname#&quot;&gt;
		&lt;/cfloop&gt;
	&lt;/cfformgroup&gt;
&lt;/cfform&gt;</code></pre>
<p>This second example uses a different approach to the same task. In order to make one checkbox per item in the query, this example uses a <code>cfloop</code> tag with a single <code>cfinput type=&quot;checkbox&quot;</code> tag nested in it.</p>
<p>The SWF file output of these two examples is practically identical, at least visually. However, behind the scenes there is a significant difference between them. Let&#8217;s compare the MXML generated by each of them (obtained by adding a <code>cfdump var=&quot;#form1#&quot;</code> to the page after the closing <code>cfform</code> tag).</p>
<p>MXML generated by Example 1 CF code:</p>
<pre><code>.
.
.
&lt;mx:Repeater id=&quot;q1&quot; dataProvider=&quot;{remoteObject_form1.getData.result.q1._items}&quot;&gt;
	&lt;mx:Form marginTop=&quot;2&quot; marginLeft=&quot;2&quot; marginBottom=&quot;2&quot; marginRight=&quot;2&quot; widthFlex=&quot;1&quot; heightFlex=&quot;1&quot;&gt;
		&lt;mx:FormItem&gt;
			&lt;mx:CheckBox selected=&quot;{UtilFunctions.isTrue(remoteObject_form1.getData.result.chk)}&quot; id=&quot;chk&quot; label=&quot;{q1.currentItem.firstname + ' ' + q1.currentItem.lastname}&quot;/&gt;
		&lt;/mx:FormItem&gt;
	&lt;/mx:Form&gt;
&lt;/mx:Repeater&gt;
.
.
.</code></pre>
<p>Notice that the <code>cfformgroup type=&quot;repeater&quot;</code> gets turned into the MXML <code>mx:Repeater</code> tag, which still contains only a single checkbox tag. In other words, when the CF gets turned into MXML (and when the MXML gets compiled into a SWF) the process of generating the dynamic checkboxes hasn&#8217;t happened yet. Not until the SWF file loads in the browser, when the ActionScript underlying the <code>mx:Repeater</code> control loops through the query and creates its child controls, is the actual process of &#8220;dynamically generating the checkbox controls&#8221; carried out.</p>
<p>On the other hand, compare this to Example 2&#8217;s MXML output:</p>
<pre><code>.
.
.
&lt;mx:VBox creationPolicy=&quot;all&quot; widthFlex=&quot;1&quot; heightFlex=&quot;1&quot;&gt;
	&lt;mx:Form marginTop=&quot;2&quot; marginLeft=&quot;2&quot; marginBottom=&quot;2&quot; marginRight=&quot;2&quot; widthFlex=&quot;1&quot; heightFlex=&quot;1&quot;&gt;
		&lt;mx:FormItem&gt;
			&lt;mx:CheckBox selected=&quot;{UtilFunctions.isTrue(remoteObject_form1.getData.result.boxMBAa_1)}&quot; id=&quot;boxMBAa_1&quot; label=&quot;Rob Smith&quot;/&gt;
		&lt;/mx:FormItem&gt;
		&lt;mx:FormItem&gt;
			&lt;mx:CheckBox selected=&quot;{UtilFunctions.isTrue(remoteObject_form1.getData.result.boxMBAa_2)}&quot; id=&quot;boxMBAa_2&quot; label=&quot;John Doe&quot;/&gt;
		&lt;/mx:FormItem&gt;
		&lt;mx:FormItem&gt;
			&lt;mx:CheckBox selected=&quot;{UtilFunctions.isTrue(remoteObject_form1.getData.result.boxMBAa_3)}&quot; id=&quot;boxMBAa_3&quot; label=&quot;Jane Doe&quot;/&gt;
		&lt;/mx:FormItem&gt;
		&lt;mx:FormItem&gt;
			&lt;mx:CheckBox selected=&quot;{UtilFunctions.isTrue(remoteObject_form1.getData.result.boxMBAa_4)}&quot; id=&quot;boxMBAa_4&quot; label=&quot;Erik Pramenter&quot;/&gt;
		&lt;/mx:FormItem&gt;
	&lt;/mx:Form&gt;
&lt;/mx:VBox&gt;
.
.
.</code></pre>
<p>As you can see, by using <code>cfloop</code> to create the checkbox controls, what (conceptually) happened was that the <code>cfloop</code> was processed and created one <code>cfinput type=&quot;checkbox&quot;</code> tag for each item in the query. Each of those items in turn became a MXML <code>mx:CheckBox</code> control. This means that the process of dynamically generating the checkboxes happened on the server, within the ColdFusion processing, rather than on the client in ActionScript (in the SWF file).</p>
<p>Again we ask, then, why does this matter?</p>
<p>Since we are dynamically generating checkboxes from a query, the assumption is that the data will be changing. With the approach in the second example any time the underlying data changes the resulting MXML that is generated by ColdFusion will also need to change. Consequently, any time the data changes (and maybe each time the page is requested, regardless of the underlying data), the server will recompile the SWF file and users will have to download the SWF file again.</p>
<p>On the other hand, with the first approach, in Example 1, no matter how the underlying data changes the MXML that is generated by the ColdFusion page will always be the same. That means that when the data changes, the CF/Flex servers don&#8217;t have to recompile the MXML and make a new SWF &#8212; they can just use the one that was already generated and is stored in the server&#8217;s cache (and the browser&#8217;s cache, if the user has browsed to this page previously).</p>
<p>As stated in the <a href="http://livedocs.macromedia.com/coldfusion/7/htmldocs/00001408.htm">ColdFusion Flash Forms documentation</a>, compiling the MXML to SWF is a time-consuming and server-resource-demanding part of the process, so it should be avoided whenever possible. Only if the number of records and number of loops over those records is large should you consider dynamically generating the SWF each time. </p>
<p>As a side note, you may be wondering how the newest data get into the SWF file running on the browser each time, if the same SWF file is reused. Once the SWF loads, it calls back to the CF server (through Flash Remoting, I believe) and loads the data.</p>
<p>Notice in the MXML the <code>mx:Repeater</code> tag has an attribute <code>dataProvider=&quot;{remoteObject_form1.getData.result.q1._items}&quot;</code>. If you look at the complete MXML generated by the form, down near the end of the MXML code this &#8220;remoteObject_form1&#8221; object (which is the Flex mechanism used to get the data) is defined in this MXML tag:</p>
<pre><code>&lt;mx:RemoteObject id=&quot;remoteObject_form1&quot; source=&quot;coldfusion.flash.adapter.CFFormAdapter&quot; endpoint=&quot;@ContextRoot()/CFFormGateway/&quot; concurrency=&quot;multiple&quot; showBusyCursor=&quot;true&quot; fault=&quot;appInitFault(event.fault)&quot;/&gt;</code></pre>
<p>And near the top there is a function &#8220;appInit&#8221; which contains this line of code which actually makes the call to load the data from the server:</p>
<pre><code>remoteObject_form1.getData(__form1_cacheid);</code></pre>
<p>And that&#8217;s how it&#8217;s done!</p>
<p>Next: <a href="../getting_data_back/">Getting meaningful data from dynamically generated fields in ColdFusion Flash Forms</a></p>
]]></content:encoded>
			<wfw:commentRss>http://probertson.com/articles/2005/08/10/creating_dynamic_form_fields/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Advice for building and debugging ColdFusion Flash Forms, from one beginner to another</title>
		<link>http://probertson.com/articles/2005/08/10/beginners_advice/</link>
		<comments>http://probertson.com/articles/2005/08/10/beginners_advice/#comments</comments>
		<pubDate>Wed, 10 Aug 2005 21:33:52 +0000</pubDate>
		<dc:creator>Paul Robertson</dc:creator>
				<category><![CDATA[Articles by Paul]]></category>
		<category><![CDATA[ColdFusion Flash Forms]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://probertson.com/articles/2005/08/10/beginners_advice/</guid>
		<description><![CDATA[Part 2 of My first foray into ColdFusion Flash Forms.
Just a sort of hodge-podge of things that were useful to me.

Write your event handler code using cfsavecontent, as I learned from Niklas at Prismix.
Chances are you will want to run more than one line of code when you press a button, and although you can’t [...]]]></description>
			<content:encoded><![CDATA[<p>Part 2 of <a href="../first_flash_forms/">My first foray into ColdFusion Flash Forms</a>.</p>
<p>Just a sort of hodge-podge of things that were useful to me.</p>
<ol>
<li><a href="http://www.prismix.com/blog/archives/2005/03/actionscript_2.cfm">Write your event handler code using cfsavecontent</a>, as I learned from <a href="http://www.prismix.com/blog/">Niklas at Prismix</a>.
<p>Chances are you will want to run more than one line of code when you press a button, and although you can’t define an ActionScript function that gets called by the button you can do the next best thing, which is this technique.</p>
</li>
<li>Give your form a name (e.g. <code>&lt;cfform type=&quot;flash&quot; name=&quot;form1&quot;&gt;</code>) and cfdump the form to see the MXML generated by it (using <code>&lt;cfdump var=&quot;#form1#&quot;&gt;</code> placed after the closing form tag).
<p>Being able to see the actual MXML output has given me tremendous insight into what is actually happening &#8220;in the guts&#8221; and consequently helped me figure out best ways or even possible ways to do things that would have been much more difficult otherwise. You even get to see the ActionScript source code for the functions that are automatically added by ColdFusion =).</p>
</li>
<li>Take some time to learn ActionScript, and use the <a href="http://livedocs.macromedia.com/flex/15/asdocs_en/">Flex reference materials</a> to understand the Flex code. I have been doing stuff with Flash/ActionScript and some Flex for a while, so I found it pretty easy to pick up. In fact, for me personally my weak point with ColdFusion Flash Forms is the ColdFusion part. I know that may not be the case for you if you are reading this, but I&#8217;m sure we can all find something new to learn =).</li>
</ol>
<p>Next: <a href="../creating_dynamic_form_fields/">Creating &#8220;dynamic&#8221; form fields in ColdFusion Flash Forms – how and why</a></p>
]]></content:encoded>
			<wfw:commentRss>http://probertson.com/articles/2005/08/10/beginners_advice/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to: Select all checkboxes in ColdFusion Flash Forms</title>
		<link>http://probertson.com/articles/2005/08/10/select_all_cf_flash_forms/</link>
		<comments>http://probertson.com/articles/2005/08/10/select_all_cf_flash_forms/#comments</comments>
		<pubDate>Wed, 10 Aug 2005 21:32:33 +0000</pubDate>
		<dc:creator>Paul Robertson</dc:creator>
				<category><![CDATA[Articles by Paul]]></category>
		<category><![CDATA[ColdFusion Flash Forms]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://probertson.com/articles/2005/08/10/select_all_cf_flash_forms/</guid>
		<description><![CDATA[Part 1 of My first foray into ColdFusion Flash Forms.
I actually came up with two different approaches to this problem, because we figured out two different ways to dynamically create form fields in Flash forms. Conceptually they are similar, of course; you have a button which calls some ActionScript code that loops through all the [...]]]></description>
			<content:encoded><![CDATA[<p>Part 1 of <a href="../first_flash_forms/">My first foray into ColdFusion Flash Forms</a>.</p>
<p>I actually came up with two different approaches to this problem, because we figured out two different ways to dynamically create form fields in Flash forms. Conceptually they are similar, of course; you have a button which calls some ActionScript code that loops through all the checkboxes and sets their &#8220;selected&#8221; property to true. Unfortunately the implementation details are pretty different.</p>
<h2>Approach 1: Using cfformgroup type=&quot;repeater&quot; (Flex creates the checkboxes)</h2>
<p><a href="/resources/2005/08/10/select_all_checkboxes_1.cfm.txt">Source Code</a></p>
<p>In this approach, the checkbox controls are dynamically created by the SWF file. The Flex code that creates them conveniently creates an array whose elements are the dynamically created checkbox controls, so we just loop through that array and set the &#8220;selected&#8221; property of each element to true (or false for &#8220;deselect&#8221;). The array variable you use has the same name as the name you give to the <code>cfinput type=&quot;checkbox&quot;</code> in your ColdFusion code. Your ColdFusion code to create the repeating checkboxes looks something like this:</p>
<pre><code>.
.
.
&lt;cfformgroup type=&quot;repeater&quot; query=&quot;q1&quot;&gt;
	&lt;cfinput type=&quot;Checkbox&quot; name=&quot;chk&quot; Label=&quot;{q1.currentItem.firstname}&quot;&gt;
&lt;/cfformgroup&gt;
.
.
.</code></pre>
<p>Flex automatically creates an array named &#8220;chk&#8221; which you can refer to in your ActionScript code, whose elements are the Checkbox controls.</p>
<h2>Approach 2: Use cfloop to create multiple checkboxes in the form</h2>
<p><a href="/resources/2005/08/10/select_all_checkboxes_2.cfm.txt">Source Code</a></p>
<p>In this approach, the checkbox controls are created in a cfloop that runs on the server. To create the &#8220;select all&#8221; functionality we just loop through our query and dynamically create the ActionScript that will be used by the &#8220;select all&#8221; button like this:</p>
<pre><code>&lt;cfsavecontent variable=&quot;selectAllClick&quot;&gt;
	&lt;cfloop query=&quot;q1&quot;&gt;
		&lt;cfoutput&gt;boxMBAa_#q1.id#.selected = true;&lt;/cfoutput&gt;
	&lt;/cfloop&gt;
&lt;/cfsavecontent&gt;</code></pre>
<p class="note">Note: Unfortunately the only ColdFusion servers I have access to belong to my employer, so I can only post source code and not working examples on my personal site. Sorry!</p>
<h2>Comparing the two approaches </h2>
<h3>Approach 1 advantage</h3>
<p>The repeating controls are actually generated in ActionScript in the SWF file, not on the server, so when the data changes the SWF file doesn’t need to be recreated by the server. See the article &#8220;<a href="../creating_dynamic_form_fields/">Creating &#8216;dynamic&#8217; form fields in ColdFusion Flash Forms - how and why</a>&#8221; for more details.</p>
<h3>Approach 2 advantage</h3>
<p>Each checkbox control is submitted as a separate form field (name/value pair); you can define the names given to the form fields. See the article &#8220;<a href="../getting_data_back/">Getting meaningful data from dynamically generated fields in ColdFusion Flash Forms</a>&#8221; for more details.</p>
<h3>Approach 1 disadvantage</h3>
<p>The checkbox values are submitted as two lists, one containing true/false values indicating whether a checkbox was checked or not, and the other containing a list of &#8220;id&#8221; values which correspond to the true/false values. See the article &#8220;<a href="../getting_data_back/">Getting meaningful data from dynamically generated fields in ColdFusion Flash Forms</a>&#8221; for more details.</p>
<h3>Approach 2 disadvantage</h3>
<p>The repeating controls are generated by the ColdFusion server before creating the MXML and subsequent SWF file. When the data changes (and maybe every time the page is requested) the server must regenerate the MXML and recompile the SWF. See the article &#8220;<a href="../creating_dynamic_form_fields/">Creating &#8216;dynamic&#8217; form fields in ColdFusion Flash Forms - how and why</a>&#8221; for more details.</p>
<p>Next: <a href="../beginners_advice/">Advice for building and debugging ColdFusion Flash Forms, from one beginner to another</a></p>
]]></content:encoded>
			<wfw:commentRss>http://probertson.com/articles/2005/08/10/select_all_cf_flash_forms/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Select all checkboxes in ColdFusion Flash Forms (Intro)</title>
		<link>http://probertson.com/articles/2005/08/10/first_flash_forms/</link>
		<comments>http://probertson.com/articles/2005/08/10/first_flash_forms/#comments</comments>
		<pubDate>Wed, 10 Aug 2005 21:27:15 +0000</pubDate>
		<dc:creator>Paul Robertson</dc:creator>
				<category><![CDATA[Articles by Paul]]></category>
		<category><![CDATA[ColdFusion Flash Forms]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Opinions]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://probertson.com/articles/2005/08/10/first_flash_forms/</guid>
		<description><![CDATA[One cool technology,
Two ways to do it, and 
Three lessons I learned
Alternate title: My first foray into ColdFusion Flash Forms
I have to admit that, while I was wowed a bit by the ColdFusion Flash Forms demos a year ago, once I heard that Flash Forms still submitted their data just like a normal HTML form, [...]]]></description>
			<content:encoded><![CDATA[<h2>One cool technology,<br />
Two ways to do it, and <br />
Three lessons I learned</h2>
<h2>Alternate title: My first foray into ColdFusion Flash Forms</h2>
<p>I have to admit that, while I was wowed a bit by the ColdFusion Flash Forms demos a year ago, once I heard that Flash Forms still submitted their data just like a normal HTML form, I lost my enthusiasm.</p>
<p>In general I don’t do a lot of ColdFusion programming any more &#8212; most of my work is in Flash or ASP.NET, although I do maintain some CF pages that I haven&#8217;t ported over to .NET yet.</p>
<p>However, a few weeks ago a friend from <a href="http://iummug.indiana.edu/">my local Macromedia Users&#8217; Group</a> contacted me with a CF Flash Forms problem he was trying to solve. He was working on a Flash form with form controls (in this case, checkboxes) that were dynamically generated from a database query, making  one checkbox per record in the query. He had that part figured out, but he wanted to add a &#8220;select all&#8221; button to the form that would select all the checkboxes. Since this was a problem that mostly involved ActionScript, and since I do have a CF MX 7 server available even though I don’t really use it, I decided to take the plunge.</p>
<p>I learned quite a bit in the process, and I&#8217;ve also gotten pretty excited about CF Flash Forms. I&#8217;m starting to see all sorts of ways I could integrate them into some of my current projects. My more CF-centric colleagues are having a good laugh over this since we have an ongoing .NET vs. ColdFusion debate =). Of course, the real solution would be to just get Flex&#8230;but maybe I&#8217;ll have to start with Flash forms so I can have some proof of the value before I make that pitch.</p>
<p>This actually only took me a couple of hours to figure out; of course it isn&#8217;t until now, several weeks later, that I have finally gotten time to write about what I learned. So without further introduction, allow me to present:</p>
<ul>
<li><a href="../select_all_cf_flash_forms/">Select all checkboxes in ColdFusion Flash Forms</a></li>
</ul>
<p>Plus three lessons I learned in the process:</p>
<ol>
<li><a href="../beginners_advice/">Advice for building and debugging CF Flash Forms, from one beginner to another</a></li>
<li><a href="../creating_dynamic_form_fields/">Creating &#8220;dynamic&#8221; form fields in ColdFusion Flash Forms - how and why</a></li>
<li> <a href="../getting_data_back/">Getting meaningful data from dynamically generated fields in ColdFusion Flash Forms</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://probertson.com/articles/2005/08/10/first_flash_forms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MXNA Reader built with CFForms</title>
		<link>http://probertson.com/articles/2005/08/01/mxna-reader-built-with-cfforms/</link>
		<comments>http://probertson.com/articles/2005/08/01/mxna-reader-built-with-cfforms/#comments</comments>
		<pubDate>Mon, 01 Aug 2005 22:03:19 +0000</pubDate>
		<dc:creator>Paul Robertson</dc:creator>
				<category><![CDATA[Articles to remember]]></category>
		<category><![CDATA[ColdFusion Flash Forms]]></category>
		<category><![CDATA[Elsewhere on the web]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://probertson.com/articles/2005/08/01/mxna-reader-built-with-cfforms/</guid>
		<description><![CDATA[ASFusion is at it again, this time with an MXNA Reader built with CFForms. Wow!
]]></description>
			<content:encoded><![CDATA[<p>ASFusion is at it again, this time with an <a href="http://www.asfusion.com/blog/entry/mxna-reader-built-with-cfforms">MXNA Reader built with CFForms</a>. Wow!</p>
]]></content:encoded>
			<wfw:commentRss>http://probertson.com/articles/2005/08/01/mxna-reader-built-with-cfforms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remoting for ColdFusion Flash Forms</title>
		<link>http://probertson.com/articles/2005/08/01/flash_forms_remoting/</link>
		<comments>http://probertson.com/articles/2005/08/01/flash_forms_remoting/#comments</comments>
		<pubDate>Mon, 01 Aug 2005 21:59:51 +0000</pubDate>
		<dc:creator>Paul Robertson</dc:creator>
				<category><![CDATA[Articles to remember]]></category>
		<category><![CDATA[ColdFusion Flash Forms]]></category>
		<category><![CDATA[Elsewhere on the web]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://probertson.com/articles/2005/08/01/flash_forms_remoting/</guid>
		<description><![CDATA[Want to use Flash Remoting in your ColdFusion Flash Forms? ASFusion has the scoop&#8230;
]]></description>
			<content:encoded><![CDATA[<p>Want to <a href="http://www.asfusion.com/blog/entry/remoting-for-coldfusion-flash-forms">use Flash Remoting in your ColdFusion Flash Forms</a>? ASFusion has the scoop&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://probertson.com/articles/2005/08/01/flash_forms_remoting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
