Solved

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

Posted on 2007-11-19
18
583 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
Comment Utility
You mean

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

Expert Comment

by:rascalpants
Comment Utility
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
Comment Utility
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
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 52

Expert Comment

by:_agx_
Comment Utility
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
Comment Utility
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_
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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_
Comment Utility
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
Comment Utility
If that works, then I was right in my first comment  :)
0
 

Author Comment

by:MOSTAGHASSI
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now