Not yet rated

Problem

Dynamic pages that are passing strings to Flash that may contain characters that need to be escaped.

Solution

A simple CFC that you pass the string to, and get back one that can be used with an inline Flash call. Fixes & and quotes. Can easily be modified, or converted into a custom tag.

Detailed explanation

<CFCOMPONENT DISPLAYNAME="FlashStringRx" 
        HINT="Takes all your &amp; worries away">


<CFFUNCTION ACCESS="public" NAME="Escape" OUTPUT="true" RETURNTYPE="string">
<!---
Code to use:
<CFINVOKE COMPONENT="FlashStringRx" METHOD="Escape" RETURNVARIABLE="getString">
<CFINVOKEARGUMENT NAME="agString" VALUE="">
<CFINVOKEARGUMENT NAME="agTrim" VALUE="0">
</CFINVOKE>

Results:
Returns the string w/ Flash chars escaped. agTrim turns Trim() on/off (1/0)
--->

<CFARGUMENT NAME="agString" DEFAULT="" REQUIRED="no" TYPE="string">
<CFARGUMENT NAME="agTrim" DEFAULT=1 REQUIRED="no" TYPE="numeric">

<CFSET ARGUMENTS.agString = Replace(ARGUMENTS.agString, "&", "%26", "All")>
<CFSET ARGUMENTS.agString = Replace(ARGUMENTS.agString, "#Chr(34)#", "&quot;", "All")>

<CFIF agTrim EQ 1>
<CFSET getString = Trim(ARGUMENTS.agString)>
<CFELSE>
<CFSET getString = ARGUMENTS.agString>
</CFIF>

<CFRETURN getString>
</CFFUNCTION>
</CFCOMPONENT>

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes