One guy's take on the web, programming, cigars, politics, Philadelphia, and whatever else comes to mind.
I'm a big fan of <CFDocument> however, the big downside I have seen is that it completely replaces the requested page with the Flashpaper interface. <CFDocument> can create Flashpaper files too, and one of the huge advantages of Flashpaper is that you can embed it. So I've written this CFC that will do just that.
Update: A while back I got all uppity about ColdFusion and Webstandards. So I came back and rewrote this to produce Webstandards compliant embeded Flash, using a variation on the Satay method.
Calling this code:
1: <cfsavecontent variable="cfdumpoutput">
2: <cfoutput>#Now()#</cfoutput>
3: </cfsavecontent>
4:
5:
6: <cfinvoke component="terry.cfc.flashpaper" method="display">
7: <cfinvokeargument name="contents" value="#cfdumpoutput#">
8: <cfinvokeargument name="orientation" value="landscape">
9: <cfinvokeargument name="filename" value="now.swf">
10: <cfinvokeargument name="width" value="450">
11: <cfinvokeargument name="height" value="200">
12: <cfinvokeargument name="overwrite" value="TRUE">
13: <cfinvokeargument name="cachedirectory" value="[a file cache]">
14: <cfinvokeargument name="cachedirectoryurl" value="[url for the cache]">
15: </cfinvoke>
Will return:
1: <cfcomponent>
2:
3: <cffunction access="private" name="write" output="false" returntype="void" hint="Writes input contents to a flashpaper file.">
4: <cfargument name="contents" type="string" required="yes" hint="The content to write to the flashpaper file.">
5: <cfargument name="filename" type="string" required="no" default="temp.swf" hint="The file name of the flashpaper we are creating.">
6: <cfargument name="orientation" type="string" required="no" default="portrait" hint="Portrait or Landscape">
7: <cfargument name="cachedirectory" type="string" required="yes" hint="The cache directory for the swf file.">
8:
9: <cfdocument filename="#arguments.cachedirectory#\#arguments.filename#" format="FlashPaper"
10: orientation="#arguments.orientation#" backgroundvisible="yes" overwrite="yes" fontembed="yes">
11: <cfoutput>
12: #arguments.contents#
13: </cfoutput>
14: </cfdocument>
15:
16: </cffunction>
17:
18: <cffunction access="private" name="embed" output="true" returntype="void" hint="Embeds a flashpaper swf in the middle of a page.">
19: <cfargument name="filename" type="string" required="no" default="temp.swf" hint="The file name of the flashpaper we are embedding.">
20: <cfargument name="width" type="numeric" required="no" default="300" hint="The width of the embedded flashpaper object.">
21: <cfargument name="height" type="numeric" required="no" default="300" hint="The height of the embedded flashpaper object.">
22: <cfargument name="cachedirectoryUrl" type="string" required="yes" hint="The url path to the cached directory.">
23:
24: <cfoutput>
25: <object type="application/x-shockwave-flash" data="#arguments.cachedirectoryUrl#/#arguments.filename#" width="#arguments.width#" height="#arguments.height#">
26: <param name="movie" value="#arguments.cachedirectoryUrl#/#arguments.filename#" />
27: <img src="http://www.numtopia.com/terry/images/style/no_flash.gif" width="200" height="300" alt="No Flash" />
28: </object>
29: </cfoutput>
30:
31: </cffunction>
32:
33: <cffunction access="public" name="display" output="true" returntype="boolean" hint="Will create and embed a flashpaper entry for input contents">
34: <cfargument name="contents" type="string" required="yes" hint="The content to write to the flashpaper file.">
35: <cfargument name="filename" type="string" required="no" default="temp.swf" hint="The file name of the flashpaper we are creating.">
36: <cfargument name="orientation" type="string" required="no" default="portrait" hint="Portrait or Landscape">
37: <cfargument name="width" type="numeric" required="no" default="300" hint="The width of the embedded flashpaper object.">
38: <cfargument name="height" type="numeric" required="no" default="300" hint="The height of the embedded flashpaper object.">
39: <cfargument name="overwrite" type="boolean" required="no" default="FALSE" hint="Whether or not to force file overwriting.">
40: <cfargument name="cachedirectory" type="string" required="yes" hint="The cache directory for the swf file.">
41: <cfargument name="cachedirectoryUrl" type="string" required="yes" hint="The url path to the cached directory.">
42:
43: <cfif overwrite or not fileExists("#arguments.cachedirectory#/#arguments.filename#")>
44: <cfinvoke method="write">
45: <cfinvokeargument name="filename" value="#arguments.filename#">
46: <cfinvokeargument name="contents" value="#arguments.contents#">
47: <cfinvokeargument name="orientation" value="#arguments.orientation#">
48: <cfinvokeargument name="cachedirectory" value="#arguments.cachedirectory#">
49: </cfinvoke>
50: </cfif>
51:
52: <cfinvoke method="embed">
53: <cfinvokeargument name="filename" value="#arguments.filename#">
54: <cfinvokeargument name="width" value="#arguments.width#">
55: <cfinvokeargument name="height" value="#arguments.height#">
56: <cfinvokeargument name="cachedirectoryurl" value="#arguments.cachedirectoryurl#">
57: </cfinvoke>
58:
59: <cfreturn TRUE>
60: </cffunction>
61:
62:
63:
64: </cfcomponent>