Why Should You Attend CFUnited 2009?
Posted By : todd sharp Posted At : April 6, 2009 1:08 PM Posted In: AIR, Networking, CFUnited, Flex, ActionScript, SlideSix
1
Why should I attend CFUnited 2009?
Why should I attend CFUnited 2009?
I've started to dabble a bit in Flex/ActionScript lately, so I'm starting to pay attention to some more Flex/AS related posts via the aggregators. This morning a post to the Flex cookbook titled Why is session info (cookies) not sent when uploading files in Firefox caught my eye since I struggled with this issue a bit recently. The article explains why session state is not maintained when using FileReference.upload(), but it doesn't explain how to workaround the issue.
To workaround the issue when uploading to a ColdFusion server, the tactic that I have come up with is to pass the jsessionid into my Flex application (via Flash vars) and then pass the jsessionid along with my file upload by appending it to the target url. I'm not 100% sure this is the best solution (feel free to comment with other ideas or suggestions), but it serves the purpose of maintaining session state which allows me to do things like ensure that a valid, logged in user is performing the upload.
Wow, it feels kinda weird to actually blog something technical here. While working on a little Flex project recently I found myself with the need to create a CF style UUID (xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx) within Flex . Flex UID's follow the 8-4-4-4-12 pattern (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). Quite a simple task really when you think about it, but here is what I came up with:
I could have gotten fancy and done it with a regular expression, but I'm sure the cost of manipulating the string in ActionScript isn't all too much to worry about.
I just had an issue on one of my work sites where a flash form was passing a dynamic data element via the url from a grid to a new page which pulled a report. The problem was that one of the dynamic values contained a "&" which obviously presents a problem. If this was pure CF I could simply use urlEncodedFormat() and urlDecode() to handle this, but since the variable in question is coming from a flash form I wasn't quite sure how to handle this one (Flash gurus can look away now).
A quick Google later, I found that ActionScript has a very similar set of functions called escape() and unescape(). I only needed to use escape() in my case, since the var was being handled by CF on the target page. I did employ the good old urlDecode() on the target page and everything worked out perfectly. Don't you love it when the solution is so simple? It's almost like the folks that make these languages know what they're doing.
There are lots of WYSIWYG text editors out there like FCKEditor and SPAW just to name a few. I've tried some of them, but they all seem somewhat bloated in my opinion. I want something lightweight and simple, but powerful enough to do some basic text formatting. I did a little Googling and found the Rich Text Editor with Disclosable Controls for Flex 2 (created by Peter Baird). This is a pretty sweet little Rich Text Editor! So my next thought was, how can I hook this into being used as a WYSIWYG editor in a simple html form? I did a little more research and learned about the Flex ExternalInterface class. The Livedocs describe the ExternalInterface as follows:
The ExternalInterface class is the External API, an application programming interface that enables straightforward communication between ActionScript and the Flash Player container; for example, an HTML page with JavaScript, or a desktop application with Flash Player embedded. Use of ExternalInterface is recommended for all JavaScript-ActionScript communication.
I took Peter's editor and added some ActionScript and compiled the SWF. I then took the generated html wrapper and added the necessary JavaScript to facilitate the communication between the containers. I next saved the wrapper as a cfm so that I could take advantage of using cf variables in prepopulating the Text Editor (as you would with a query for example). The final result is pretty sweet. The RTE is prepopulated from a cf variable, all changes made in the RTE immediately update a textarea (which could easily be hidden) in the html form and the resulting html text is submitted with the html form (which could then be saved in the db). This is my first experience in building a Flex application, so I'm not going to release the code quite yet (it's a mess anyways!!) I'm not quite sure what step to take next. I suppose It's possible that this could be packaged and used as a cfinclude within any html form. Anyone have any other ideas?
If you write Coldfusion, you've likely visited cflib.org at some point and used one or more of the excellent UDF's posted there. I've often wondered why there is no single repository for common Actionscript functions like cflib. There are tons of custom functions out there, but I've yet to find a single source that is structured in an easy to use format. Since I've been using Flash Forms so heavily, I often find myself searching for a custom function for string manipulation and other purposes and I realized that many of the ones that I find could be easily reused in different applications. Many are written for use in Flash or Flex, but can also be used in Flash Forms with little or no modification. With that in mind, here's a short survey:
If there is enough interest, I would like to get a site up and running. If anyone is interested in helping out with the design and/or administration, please let me know. Also, if someone would like to offer to host the site, I wouldn't turn them down ;) - or I'll host on my own.
I got into a discussion today with someone on an old thread on Ray Camden's blog who was having issues with the way his dates were being displayed in a cfgrid. The problem he was having was that he would choose a date in a datefield, then submit the form and update the database with the date - For example:
One of my coworkers has been working on a project tracking tool and had a need to automatically calculate some dates based on the selected items and other dates (such as due date). I found this function over on Jeff Tapper's blog, but the function needed to add (and subtract) business days, not just calendar days. As a result I threw together another script to work in conjuction with Jeff's script to make it work for business days. There's nothing pretty about this code. I've been on conference calls for 6-7 hours a day for three weeks, so trust me - this one has little thought put into it. But it works - and with a little work it could be cleaned up.
The source for the example is attached to this post if you'd like to download.
Enjoy & Happy Friday!
Here's an example of creating a usable MXML popup form from within a flash form. Despite the some of the evil uses of popups, they can actually be helpful tools for capturing user data.

As a follow up to my original post, here's an example of creating a combobox cell renderer for a cfgrid which is populated with a query rather than a hardcoded dataprovider. The trick is to use flash remoting to get the query, set a global variable containing the results, then call the renderer and use the global variable to set the combobox dataprovider.
The example still looks the same, but obviously this method is much more dynamic. There is one change in the AS file for the renderer. Since we're using a query from remoting, we can't access combo.selectedItem.data. Instead, we reference the column name from the query - in this case it's combo.selectedItem.priority.
Update: Download the Code.
selectRendererWithQuery.cfm
cellRendererSelect.cfc
ComboBoxCellNew.as