Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Cookie String

  1. #1
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cookie String

    I am using a function that successfully loads mp3s into a Flash player, eg:

    PHP Code:
    appendPlaylist('1','example3.mp3','My Artist','My Title3','My URL','image.jpg'); 
    I have modified the function to set and update a cookie each time the function is called - this works fine!

    This however does not:

    PHP Code:
    function load()
    {
    var 
    myname ="playlist"
    var tracks getCookie(myname)  // only one song in the cookie for testing
    alert(tracks); // this displays: '1','example3.mp3','My Artist','My Title3','My URL','image.jpg'&
    if (tracks != "") {
    var 
    tracklist unescape(tracks)
    tracklist trimRecursive(tracklist)  // this function strips the trailing '&' and any whitespace
    var track tracklist.split("&")
    for(
    0track.lengthi++){
    alert(track[i]);  // this displays: '1','example3.mp3','My Artist','My Title3','My URL','image.jpg'
    appendPlaylist(track[i]);
    }
    }

    It loads a "blank" track into the player If I substitute the following within the load() function itself, it works just fine:

    PHP Code:
    appendPlaylist('1','example3.mp3','My Artist','My Title3','My URL','image.jpg'); 
    To me its a mystery - could some kind soul please explain why?

    Thanks!

    TheMuffin
    Last edited by TheMuffin; 03-26-2007 at 05:06 AM.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by TheMuffin View Post
    Code:
    function load()
    {
    var myname ="playlist"
    var tracks = getCookie(myname)  // only one song in the cookie for testing
    alert(tracks); // this displays: '1','example3.mp3','My Artist','My Title3','My URL','image.jpg'&
    if (tracks != "") {
    var tracklist = unescape(tracks)
    tracklist = trimRecursive(tracklist)  // this function strips the trailing '&' and any whitespace
    var track = tracklist.split("&")
    for(i = 0; i < track.length; i++){
    alert(track[i]);  // this displays: '1','example3.mp3','My Artist','My Title3','My URL','image.jpg'
    appendPlaylist(track[i]);
    }
    }
    }
    Are u sure ur calling it right ur calling appendPlaylist inside a for loop with a single argument...

  • #3
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No I am not sure - I am new to javascript and that is why I ask here for help

    To my mind, the variable track[i] contains a string with six arguments (as I see in the alert and show in my comment within the code). Are you saying that I must split track[i] into separate variables and then use those in the function?

    TheMuffin

  • #4
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok this works... I cleaned up any quotes in the cookie first:

    PHP Code:
    function load()
    {
    var 
    myname ="playlist"
    var tracks getCookie(myname)
    if (
    tracks != "") {
    var 
    tracklist unescape(tracks)
    tracklist trimRecursive(tracklist)
    var 
    track tracklist.split("&")
    for(
    0track[i].lengthi++){
    var 
    mylist track[i].split(",")
    appendPlaylist(mylist[0],mylist[1],mylist[2],mylist[3],mylist[4],mylist[5]);
    }
    }

    Could somebody coach me on how to delay each iteration of the for loop? - the appendPlaylist function is asyncronous Ajax - I can get a return variable from the player for each call with appendPlaylist.

    Thanks!

    TheMuffin
    Last edited by TheMuffin; 03-26-2007 at 11:20 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •