Loading a SWF file using a coldfusion variable

Hello!

I have a website on which I need to display a .swf tutorial.  There are 50+ different tutorial files.  I would like to use 1 page to display the tutorials and just dynamically pass the swf file name into the object tag.

I have a database in which I store the .swf file name and it's associated topic ID.  So the information stored in the database is:

TopicID, fileLocation    (example:    1, myfile)

I'm passing the topicID through a URL variable which then drives my query:

<cfquery datasource="mydatabase" name="getCurrentTopic">
            SELECT fileLocation
            FROM Topics
            WHERE TopicID = #url.location#
</cfquery>

If I quickly output the results of this query - it is displaying the correct fileLocation - so that much is working.

After that query, I have the following code:


<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="750" height="500" id="<cfoutput query="getCurrentTopic">#fileLocation#</cfoutput>" align="middle">
                        <param name="movie" value="<cfoutput query="getCurrentTopic">#fileLocation#</cfoutput>.swf" />
                        <param name="quality" value="high" />
                        <param name="bgcolor" value="#ffffff" />
                        <param name="play" value="true" />
                        <param name="loop" value="true" />
                        <param name="wmode" value="window" />
                        <param name="scale" value="showall" />
                        <param name="menu" value="true" />
                        <param name="devicefont" value="false" />
                        <param name="salign" value="" />
                        <param name="allowScriptAccess" value="sameDomain" />
                        <!--[if !IE]>-->
                        <object type="application/x-shockwave-flash" data="<cfoutput query="getCurrentTopic">#fileLocation#</cfoutput>" width="750" height="500">
                              <param name="movie" value="<cfoutput query="getCurrentTopic">#fileLocation#</cfoutput>.swf" />
                              <param name="quality" value="high" />
                              <param name="bgcolor" value="#ffffff" />
                              <param name="play" value="true" />
                              <param name="loop" value="true" />
                              <param name="wmode" value="window" />
                              <param name="scale" value="showall" />
                              <param name="menu" value="true" />
                              <param name="devicefont" value="false" />
                              <param name="salign" value="" />
                              <param name="allowScriptAccess" value="sameDomain" />
                        <!--<![endif]-->
                              <a href="http://www.adobe.com/go/getflash">
                                    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                              </a>
                        <!--[if !IE]>-->
                        </object>
                        <!--<![endif]-->
                  </object>


The .swf file is located in the same directory as the .cfm file.  However, when I load this page, I only get a large white box and the "get flash" image/link.  The swf file does not load.

I tried testing using the same structure on an <img> tag for an image file (that has the same name as the swf file except that it has a .jpg extension) and that works perfectly.  I just can't seem to get the object tag to take my cf variable.

Thoughts?
tbarber210Asked:
Who is Participating?
 
_agx_Connect With a Mentor Commented:
> I'm not sure why the FileExists function doesn't find the file though...

My bad.  FileExists expects a physical path ie "c:\temp\sub\yourFile.swf".  I omitted ExpandPath(), which you need it to convert a URL to a physical path.

ie <cfif FileExists( ExpandPath("/path/to/yourFile.swf") )>

    > I try to move the file into a subfolder (for organization purposes), it will not let me do:
As long as "swf/#fileLocation#.swf" a real path, relative to your script, that should work.  Do a "view source". What html is generated?

May not not be the problem, but I'd suggest using <cfoutput>  not cfoutput query. Because if multiple records are found, the parameter will be wrong.
0
 
_agx_Commented:
What is the value of #fileLocation#?  Sounds like it could be a wrong value or path.  The parameter value should be a url like:

            http://yourserver.com/path/to/yourFile.swf OR ...
            /path/to/yourFile.swf  OR ...
            yourFile.swf                                       <=== relative to *.cfm script

Verify the file actually exists. If it does, try temporarily hard coding the value.

     <cfif FileExists("/path/to/yourFile.swf")>File found<cfelse>Not found</cfif>
     ....
     <param name="movie" value=""/path/to/yourFile.swf" />

0
 
tbarber210Author Commented:
#fileLocation# includes the file name without the extension.  So if the file name is myfile.swf, #fileLocation# contains "myfile".

Interestingly enough, when I try the "FileExists" function, it says that the file does not exist.

However, if I change over the embedding code to to be an <Object> tag with an internal <embed>  tag, it does display.  Perhaps there is something about the newer <object> & <object> code sequence that doesn't allow it to display properly?  I'm not sure... but I do get the file to display with the <object> and <embed> tags.  

It does have problems if I try to move the file into a subfolder (for organization purposes), it will not let me do:

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
                     WIDTH="750" HEIGHT="500" id="<cfoutput query="getCurrentTopic">#fileLocation#</cfoutput>">

                <PARAM NAME=movie VALUE="<cfoutput query="getCurrentTopic">swf/#fileLocation#.swf</cfoutput>">

                <PARAM NAME=quality VALUE=high>

                <PARAM NAME=bgcolor VALUE=#FFFFFF>

                <EMBED src="<cfoutput query="getCurrentTopic">swf/#fileLocation#.swf</cfoutput>" quality=high bgcolor=#FFFFFF WIDTH="800" HEIGHT="600"
NAME="<cfoutput query="getCurrentTopic">#fileLocation#</cfoutput>" ALIGN="" TYPE="application/x-shockwave-flash">
                </EMBED>



I'm not sure why the FileExists function doesn't find the file though...
0
 
tbarber210Author Commented:
Ah!  That fixed it!  Thanks for the help... it's now working perfectly!
0
 
_agx_Commented:
Welcome :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.