Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 607
  • Last Modified:

How can i pass a file name path to this javascript on a cfm page?

Hello all,

On a page (playsong.cfm) i have this query and retieve a filed (trackfilepath)
which contain mp3 file name ,like track1.mp3 ,i want that pass the path (<location>) of
this file to the javascript below ,please let me know that how can i do it?

Thanks

<cfparam name="url.trackfilepath" default="">
<cfquery name="recordset1" datasource="musicarchiveDS" >
select   trackfilepath
from   tbTracks
where trackfilepath like '#url.trackfilepath#'
</cfquery>

<script type="text/javascript">
      // <![CDATA[

      var so = new SWFObject("ep_player.swf", "ep_player", "269", "226", "9",

"#FFFFFF");
      so.addVariable("skin", "skins/nobius_platinum/skin.xml");
      so.addVariable("file",

"<location>http://localhost/magazine/musicarchive/songtracks/track1.mp3</locati

on><creator>Song Creator</creator><title>Song Title</title>");
      so.addVariable("autoplay", "false");
      so.addVariable("shuffle", "false");
      so.addVariable("buffertime", "1");
      so.write("flashcontent");

      // ]]>
</script>
0
MOSTAGHASSI
Asked:
MOSTAGHASSI
  • 9
  • 5
  • 2
  • +1
1 Solution
 
Michel PlungjanIT ExpertCommented:
You mean

<location>#trackfilepath#</location>
0
 
rascalpantsCommented:
are you trying to pass in some XML as a variable?  if not, then there is no reason to have that mark up there.

just pass the url as teh variable.


can you further explain what you have working...  and were the application fails.


rp
eeZAPE
0
 
MOSTAGHASSIAuthor Commented:
Thanks for your comments.
I have a folder that contain my mp3 files suppose 100 files from track1.mp3  to track100 this folder is Songtracks   in coldfusion query i retieve the file name   suppose track40.mp3 then i want put the path of this file in javascript codes that you see in part of <location> so all part  of of codes are without any changing except the part of <location>  so if i retieve  track40.mp3  then the <location> must be :

<location>http://localhost/magazine/musicarchive/songtracks/track40.mp3</location>
and for track 23.mp3 e.g is:
<location>http://localhost/magazine/musicarchive/songtracks/track23.mp3</location>

so i must pass this file name in javascript as i mentioned above.


0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
_agx_Commented:
So you just want to pass the url  like this?

<script type="text/javascript">
	<cfoutput>
		var #ToScript(recordset1.trackfilepath, "trackName")#;
	</cfoutput>
      // <![CDATA[
      var so = new SWFObject("ep_player.swf", "ep_player", "269", "226", "9", "#FFFFFF");
      so.addVariable("skin", "skins/nobius_platinum/skin.xml");
      so.addVariable("file", "http://localhost/magazine/musicarchive/songtracks/"+ trackName);
      so.addVariable("autoplay", "false");
      so.addVariable("shuffle", "false");
      so.addVariable("buffertime", "1");
      so.write("flashcontent");
      // ]]>
</script>

Open in new window

0
 
MOSTAGHASSIAuthor Commented:
Hi agx,
Yes, this is the things that i want ,but would you please write that line as compelet? my mean is this line below ,i put the  sign of (") around http but the codes goes to gray color and not work.

"<location>http://localhost/magazine/musicarchive/songtracks/track1.mp3</locati

on><creator>Song Creator</creator><title>Song Title</title>");
0
 
MOSTAGHASSIAuthor Commented:
I write like this and not above:
"<location> "http://localhost/magazine/musicarchive/songtracks/"+trackName</location>

<creator>Song Creator</creator><title>Song Title</title>");

but the part of url goes to gray color,and cannot recognize the url,i have tested with putting paranteses around url also,ofcourse the cf tag is in my code as you have written:
<cfoutput>
var #ToScript(recordset1.trackfilepath, "trackName")#;
</cfoutput>


0
 
MOSTAGHASSIAuthor Commented:
the complelet code that i write is this:
so.addVariable ("file",
 "<location> "http://localhost/magazine/musicarchive/songtracks/"+  trackName
</location><creator>Song Creator</creator><title>Song Title</title>");
0
 
rascalpantsCommented:
but you are still passing in what looks to be XML data...  is this correct?

if so, then most likely your code in Flash is not parsing the XML correctly....

can you post the actionscript for me...


rp
eeZAPE
0
 
MOSTAGHASSIAuthor Commented:
Yes you are right ,but i don't have action script ,this problem is regarding sending that path of a mp3 file in a javascript and and then it call flash mp3 player, i want to buy it but i'm trying to test it first ,in javascript we can send a playlist.xml of only a file as you see above, as agx has written in coldfusion i must retieve the file name and the determine the path in javascript ,the solution of agx is right but around the variable is that  there are this mark(") in  trackname variable is e.g

trackname="Track2.mp3";;  while i need that it be  trackname=Track2.mp3 or as he has used + trackname but it does not detremine the right path.
0
 
_agx_Commented:
MOSTAGHASSI,

The quotes " are just used to enclose the javascript variable name definition.  The final string should not contain quotes.  It should look like this.  Is this not the correct path?

     http://localhost/magazine/musicarchive/songtracks/Track2.mp

Two other options are
<!--- option 1 --->
<script type="text/javascript">
	<cfoutput>
    	var #ToScript("http://localhost/magazine/musicarchive/songtracks/#recordset1.trackfilepath#", "trackPath")#;
    </cfoutput>
    // <![CDATA[
    var so = new SWFObject("ep_player.swf", "ep_player", "269", "226", "9", "#FFFFFF");
    so.addVariable("skin", "skins/nobius_platinum/skin.xml");
    so.addVariable("file", trackPath);
    so.addVariable("autoplay", "false");
    so.addVariable("shuffle", "false");
    so.addVariable("buffertime", "1");
    so.write("flashcontent");
    // ]]>
</script>
<!--- option 2 --->
<script type="text/javascript">
	// <![CDATA[
    var so = new SWFObject("ep_player.swf", "ep_player", "269", "226", "9", "#FFFFFF");
    so.addVariable("skin", "skins/nobius_platinum/skin.xml");
    <cfoutput>
    so.addVariable("file", "http://localhost/magazine/musicarchive/songtracks/#recordset1.trackfilepath#");
    </cfoutput>
    so.addVariable("autoplay", "false");
    so.addVariable("shuffle", "false");
    so.addVariable("buffertime", "1");
    so.write("flashcontent");
    // ]]>
</script>

Open in new window

0
 
MOSTAGHASSIAuthor Commented:
Yes ,but you omit a part of code i must write the compelet code inside the      so.addVariable

the complete code is  like below and it start with  "file",<location> ,you omit the part of <location> that start before http
 so.addVariable("file",

"<location>http://localhost/magazine/musicarchive/songtracks/track1.mp3</locati

on><creator>Song Creator</creator><title>Song Title</title>");

istead of url that start with http if i write like this below it does not work and i must write the compelet code

 so.addVariable("file",

"<location>"http://localhost/magazine/musicarchive/songtracks/#recordset1.trackfilepath#"</locati

on><creator>Song Creator</creator><title>Song Title</title>");

you omit the part of <location> at the start of code,for path you are right but when i put between tag of <location> as above it does not work
0
 
_agx_Commented:
I assume you enclosed it in cfoutput tags?  Otherwise it won't evaluate #recordset1.trackfilepath#.

> so.addVariable("file",
> "<location>"http://localhost/magazine/musicarchive/songtracks/#recordset1.trackfilepath#"</locati
> on><creator>Song Creator</creator><title>Song Title</title>");

Is that valid syntax for the object you're using?  I would have thought it just accepted a url.

If you hard-code the information, does it work?  If it doesn't work then its a problem with your syntax, not the CF code.


<!--- 
     Verify the track path / url is correct
--->
<script type="text/javascript">
    // <![CDATA[
    var so = new SWFObject("ep_player.swf", "ep_player", "269", "226", "9", "#FFFFFF");
    so.addVariable("skin", "skins/nobius_platinum/skin.xml");
    so.addVariable("file", "<location>http://localhost/magazine/musicarchive/songtracks/Track2.mp3</location><creator>Song Creator</creator><title>Song Title</title>");
    so.addVariable("autoplay", "false");
    so.addVariable("shuffle", "false");
    so.addVariable("buffertime", "1");
    so.write("flashcontent");
    // ]]>
</script>

Open in new window

0
 
MOSTAGHASSIAuthor Commented:
The code that you have written in the box work very well, but we need that instead of Track2.mp3 put the variable that contain the name of mp3 file  ,and suppose that we come with Track2.mp3  to this .cfm page  inside the trackname(that you have written between <cfoutput> tags) i see that there is like this:
Trackname="Track2.mp3";;   (there are quote and semicolom)   but if i have like this:
Trackname=Track2.mp3   i can put the  Trackname instead of Track2.mp3 in the url .
0
 
_agx_Commented:
As I mentioned on the other thread, the ";;" is not actually part of the variable TrackName. But you can remove it.  Try the attached.
<script type="text/javascript">
    <cfoutput>
       var #ToScript("http://localhost/magazine/musicarchive/songtracks/#recordset1.trackfilepath#", "trackPath")#
    </cfoutput>
    // <![CDATA[
    var so = new SWFObject("ep_player.swf", "ep_player", "269", "226", "9", "#FFFFFF");
    so.addVariable("skin", "skins/nobius_platinum/skin.xml");
    so.addVariable("file", "<location>"+ trackName +"</location><creator>Song Creator</creator><title>Song Title</title>");
    so.addVariable("autoplay", "false");
    so.addVariable("shuffle", "false");
    so.addVariable("buffertime", "1");
    so.write("flashcontent");
    // ]]>
</script>

Open in new window

0
 
MOSTAGHASSIAuthor Commented:
No,the object bring the mp3 player but because cannot find the right path ,write message that error on loading mp3 file.
Ofcours on Toscript you have written  "trackPath"   and between <location> tags i think it must be trackPath   and i put trackPath ,but it doesnot work,and the problem is regarding recognizing of path,because it works with e.g a track name like Track2.mp3
0
 
_agx_Commented:
You mean it doesn't accept a javascript variable?

What happens if you omit the javascript variable entirely like this. Watch the line wrapping

<script type="text/javascript">
    // <![CDATA[
    var so = new SWFObject("ep_player.swf", "ep_player", "269", "226", "9", "#FFFFFF");
    so.addVariable("skin", "skins/nobius_platinum/skin.xml");
	<cfoutput>
    so.addVariable("file", "<location>http://localhost/magazine/musicarchive/songtracks/#recordset1.trackfilepath#</location><creator>Song Creator</creator><title>Song Title</title>");
	</cfoutput>
    so.addVariable("autoplay", "false");
    so.addVariable("shuffle", "false");
    so.addVariable("buffertime", "1");
    so.write("flashcontent");
    // ]]>
</script>

Open in new window

0
 
Michel PlungjanIT ExpertCommented:
If that works, then I was right in my first comment  :)
0
 
MOSTAGHASSIAuthor Commented:
Hi agx,
Your last solution  before this one that i past below works and i had a mistake,sorry for this,and thanks a lot for this ,i appreciate .

<script type="text/javascript">
    <cfoutput>
       var #ToScript("http://localhost/magazine/musicarchive/songtracks/#recordset1.trackfilepath#", "trackPath")#
    </cfoutput>
    // <![CDATA[
    var so = new SWFObject("ep_player.swf", "ep_player", "269", "226", "9", "#FFFFFF");
    so.addVariable("skin", "skins/nobius_platinum/skin.xml");
    so.addVariable("file", "<location>"+ trackPath +"</location><creator>Song Creator</creator><title>Song Title</title>");
    so.addVariable("autoplay", "false");
    so.addVariable("shuffle", "false");
    so.addVariable("buffertime", "1");
    so.write("flashcontent");
    // ]]>
</script>
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.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 9
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now