Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2007-11-19
18
Medium Priority
?
602 Views
Last Modified: 2012-06-27
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
Comment
Question by:MOSTAGHASSI
  • 9
  • 5
  • 2
  • +1
18 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20322690
You mean

<location>#trackfilepath#</location>
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 20323085
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
 

Author Comment

by:MOSTAGHASSI
ID: 20325041
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 52

Expert Comment

by:_agx_
ID: 20325311
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
 

Author Comment

by:MOSTAGHASSI
ID: 20326062
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
 

Author Comment

by:MOSTAGHASSI
ID: 20326991
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
 

Author Comment

by:MOSTAGHASSI
ID: 20327017
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
 
LVL 22

Expert Comment

by:rascalpants
ID: 20327957
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
 

Author Comment

by:MOSTAGHASSI
ID: 20329413
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
 
LVL 52

Expert Comment

by:_agx_
ID: 20330125
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
 

Author Comment

by:MOSTAGHASSI
ID: 20330408
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
 
LVL 52

Expert Comment

by:_agx_
ID: 20330525
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
 

Author Comment

by:MOSTAGHASSI
ID: 20330681
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
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 20330822
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
 

Author Comment

by:MOSTAGHASSI
ID: 20331018
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
 
LVL 52

Expert Comment

by:_agx_
ID: 20331059
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20333660
If that works, then I was right in my first comment  :)
0
 

Author Comment

by:MOSTAGHASSI
ID: 20334616
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question