Intermediate Contest Entry 8

Welcome to the eighth entry in the Intermediate ColdFusion Contest. The earlier entries may be found at the end of this post. Today's entry is from Scott Johnson. Before reading on, please check his application here. You can download his code from the download link at the bottom. Please respect the copyright of the creator.

Wow. I like Flash Forms - but I was amazed at this one. I was certain he was using a normal Flash file, but I noticed the loader looked just like a normal Flash Form. I opened up the code and saw that I was right - Flash Forms. Now - to be honest - he is pushing things a bit. He uses Flash Remoting and certainly that is the kind of thing that may not work in future versions of ColdFusion.

I am absolutely in love with this Flash Form - but due to the size - I'm going to suggest people download the zip and check out the file there. Not only does he use remoting, he employs some custom styles as well.

So with all that raving - now I'm going to nit pick. First off, his application.cfm file looks like so: (Note that I had to modify the appPath variable for my server.)

<cfapplication sessionmanagement="true" name="BlackJack">

<!--- PLayers starting amount of money is set --->
<cfset APPLICATION.startAmount = 1000>
<!--- Set the path that the application resides in, with respect to the host --->

<cfset APPLICATION.appPath = "sjohnson.bj">

<!--- if there is no blackjack cfc or if init variable is defined, create a new instance --->
<cfif NOT IsDefined("SESSION.BlackJack") OR IsDefined("URL.init")>
   <cfobject component="components.BlackJack" name="SESSION.BlackJack">
   <!--- initialize the cfc --->
   <cfset SESSION.BlackJack.Init()>
</cfif>

He correctly caches his session variable, but doesn't do the same for his application variables. Therefore, every hit will recreate both startAmount and appPath in the Application scope. Not a horrible mistake - but something he should address.

Oh - and he didn't var scope. Getting tired of me saying that yet?

One last note. I had to modify the darn appPath variable everytime I moved the code. Can anyone think of a good way to create a "dot" path from the current folder?

Earlier Entries:

Comments

Ray, why do you say that Flash Remoting may not be included in future versions of CF? Macromedia has already announced it's inclusion in Flex Builder 2. I honestly don't see them getting rid of it anytime soon. Maybe deprecating it at some point if they come out with something better, but like everything else, it will probably be around for quite a while in support of backward compatability.
# Posted By Rob Brooks-Bilson | 12/1/05 10:48 PM
Ray thinks Macromedia will take it out of future versions of ColdFusion b/c of potential security risks. but, he'll have to explain more in detail. i just remember him saying that in a recent blog about flash forms and remoting.

By the way, I like this entry the best so far. that ajax stuff is a bit too clumsy to me. this is a solid game. one thing i like to see (that this entry did not have, but some others did) was the point total of my hand as i'm hitting. and the reason is sometimes i'll have like 5 or 6 cards and i have add them up in my head. that's not a big deal but what if i'm 1 point off. that could weigh my risks out differently when deciding whether to hit or stay.
# Posted By Brett Liotta | 12/1/05 11:24 PM
Love flash forms and remoting; but I wouldn't get too involved with Flash Forms, as I believe they'll get completely replaced by Flex 2.0.

I had 7 cards at one point. After that, the 7th card was never removed from stage.

I don't like the fact that it won't tell me the scope or count how may point I have in my hand.
# Posted By Rob Gonda | 12/1/05 11:36 PM
Commenting on the 'dot' path from the current folder... I know what you mean, and they way I got around that in my latest project was creating an ObjectFactory and initialize it in my Application.cfm/cfc ... The Object knows the path to every other component, and I only initialize objects through the factory. It's a little extreme, but I think it will save me in many aspects... f.e. objects that communicate with each other, but must be declared a singletons ... the objectFactory returns me the singleton instance that's already loaded...

I can provide examples if someone is interested...

Cheers

-Rob
# Posted By Rob Gonda | 12/1/05 11:40 PM
I'm sorry. What I meant was - the ability to use FR in Flash Forms may be removed. Not FR itself.
# Posted By Raymond Camden | 12/2/05 12:22 AM
i definitely dig the flash interface...but since i accept the fact that i'll never be a user interface developer (i just suck at that whole design thing), i'm really much more interested in code.

agreed with Brett that it would have been really nice to display the current players totals with each card draw.

also i seem to have broken it by betting $1000 right off (yeah, i'm a gambler) and losing (ok, not a good gambler). the game didn't end, but i was unable to place a bet (kept getting an alert box telling me to "wager -1000 or less" in spite of the fact that i was unable to wager anything). hit the back button a few times to get back to the blog entry, clicked the link to start the game, bet $1000 again, lost (really not a good gambler), and now it tells me to "wager -2000 or less".

not gonna harp too much on the validation. my entry should be coming up soon and i already know a few things that are going to come up that are validation-related (among other things) :) just bringing it up in case scott wants to check into the code and see what's up.
# Posted By charlie griefer | 12/2/05 12:47 AM
Ahh yes, the sixth card won't be cleared from the stage. I originally made the game with six cards. It is possible (although unlikely) to get up to 12 cards on a hand, but I planned for six and saved the real estate. I started testing and came upon a 7 card hand, so I added the area extra card space. There is a clearForm function that clears the card images, I didnt update that function to clear the 7th card slot. Simple fix, but still a problem.

With Flex Builder 2 on the horizon, it would seems likely that Macromedia would stray away from flash remoting and limit what you can do with flash forms through coldfusion. With some patience and actionscript know-how, you can build exciting RIAs with just coldfusion, basically another avenue to build simple flex apps. To define Flex and Coldfusion together as separate products that complement each other, I think they will need to limit what flash forms can do to avoid confusion.
# Posted By Scott Johnson | 12/2/05 1:00 AM
What I used before there where mappings was the following piece of code to get a "../../" path from the current directory. Just place it in the Application.cfm

<cfset request.rootpath = "#mid(Rereplace(cgi.path_info,'/*[^/]*/*','../','all'),4,(len(cgi.path_info)-4))#">
# Posted By Tjarko Rikkerink | 12/2/05 7:59 AM
although the flash forms are cool, there is no count of my cards, and that just erks me. there is also a problem with something as it locked up my browser. ff 1.5 :( not sure if its ff or flash, but something is up between the two i think.
# Posted By tony of the weeg clan | 12/2/05 9:56 AM
This entry is throwing an entry when trying to deal.
# Posted By Scott Stroz | 12/8/05 10:22 AM
I just tested and it worked fine for me.
# Posted By Raymond Camden | 12/8/05 10:29 AM