HOME | FERGUSON Digital Blog

CALLER Scope counting calls

ColdFusion Add comments

A few years ago an update to Internet Explorer and "Active X activation issues" caused a bounding box to be displayed around all flash objects. I needed to come up with a solution to bypass the imposed requirement for customers to click on the OBJECT tag to activate.

I chose the SWFObject as a work around but it meant re-writing every page with a hardcoded fix. Not a good plan for a corporate web-presence that was at the very core of its mission execution.

Here is a link to SWFObject.

The solution was to design a custom tag that would detect which was the first SWF on the page and include the SWFObject call to load the JavaScript. Using the custom tag CALLER scope and counting how many times the custom tag is called per page, the code below adds the JavaScript on the first call and skips past each subsequent call. This way the page doesn't return multiple functions with the same name, reduces clutter, speeds up processing, and delivers content with control over the SWF attributes...all without hard coding pages.

<cfparam name="CALLER.cfFlashMX" default="0">
<cfparam name="ATTRIBUTES.FlashHeight" default="0">
<cfparam name="ATTRIBUTES.FlashWidth" default="0">
<cfparam name="ATTRIBUTES.FlashVersion" default="10.0.45.2">
<cfparam name="ATTRIBUTES.FlashColor" default="FFFFFF">
<cfparam name="ATTRIBUTES.FlashWMode" default="transparent">

<cfset CALLER.cfFlashMX=CALLER.cfFlashMX+1>
<cfif CALLER.cfFlashMX EQ 1>
   <script type="text/javascript" src="/Media/fnSWFobject.js"></script>
</cfif>

<cfoutput>
   <script type="text/javascript">
      var so#CALLER.cfFlashMX# = new SWFObject("#ATTRIBUTES.FlashFile#", "#ATTRIBUTES.FlashName#", "#ATTRIBUTES.FlashWidth#", "#ATTRIBUTES.FlashHeight#", "#ATTRIBUTES.FlashVersion#", "#ATTRIBUTES.FlashColor#");
      so#CALLER.cfFlashMX#.addParam("wmode", "#ATTRIBUTES.FlashWMode#");
      so#CALLER.cfFlashMX#.addParam("menu", "false");
      so#CALLER.cfFlashMX#.write("flashcontent#CALLER.cfFlashMX#");
   </script>
</cfoutput>


This example called SWFObject v1.5 when it was originally designed.

If you find this post useful please leave a comment and let me know how you used the information.

0 responses to “CALLER Scope counting calls”

Leave a Reply



© Copyright 1997-2024, All Rights Reserved Coldfusion and MS SQL2008
Powered by Mango Blog.   Design by FERGUSON Digital
o:Event name="beforeHtmlBodyEnd" />