SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2000
    Location
    Halifax, Nova Scotia
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript Cookies with Flash - need some advice

    Found a script on the 'net that I want to try and set up, thought that it would be straight forward but finding out that I may be wrong.

    It is a simple JavaScript cookie that creates a text box to type into and then store the information on the computer. Once the user comes back again it shows the same information and is like a notepad that is a neat tool!

    Want to have something similar for a Flash file on site, but can't seem to get it to work.

    The cookie.js is saved within the same directory.

    Have the following code in the head of the HTML document:
    <SCRIPT LANGUAGE="JavaScript" SRC="cookie.js"><!--
    // --></SCRIPT>
    <SCRIPT LANGUAGE="JavaScript"><!--

    function loadNotes() {
    var cookie=document.cookie
    if(nameDefined(cookie,"Notes")) {
    notes=getCookieValue(cookie,"Notes")
    notes=decode(notes)
    }else notes=""
    document.forms[0].notesArea.value=notes
    }
    function saveNotes() {
    notes=window.document.forms[0].notesArea.value
    notes=encode(notes)
    var newCookie = "Notes="+notes+"; expires="
    newCookie += "Tuesday, 09-Nov-10 23:12:40 GMT"
    document.cookie=newCookie
    }
    function encode(s) {
    t=""
    for(var i=0;i<s.length;++i) {
    ch=s.charAt(i)
    if(ch=="/") t += "//"
    else if(ch==" ") t += "/b"
    else if(ch==",") t += "/."
    else if(ch==";") t += "/:"
    else if(ch=="\n") t += "/n"
    else if(ch=="\r") t += "/r"
    else if(ch=="\t") t += "/t"
    else if(ch=="\b") t += "/b"
    else t += ch
    }
    return t
    }
    function decode(s) {
    // Decode the encoded cookie value
    t=""
    if(s==null) return t
    for(var i=0;i<s.length;++i) {
    var ch=s.charAt(i)
    if(ch=="/") {
    ++i
    if(i<s.length){
    ch=s.charAt(i)
    if(ch=="/") t += ch
    else if(ch==".") t += ","
    else if(ch==":") t += ";"
    else if(ch=="n") t += "\n"
    else if(ch=="r") t += "\r"
    else if(ch=="t") t += "\t"
    else if(ch=="b") t += " "
    }
    }else t += ch
    }
    return t
    }
    // --></SCRIPT>

    Then on the text box movie clip inside the flash file have the following:

    onClipEvent (load) {
    getURL ("javascript:loadnotes()");
    }

    The movie clip is simply an 'input' text box, with a variable of notesArea for the options.

    On the button to submit have:
    on (release) {
    getURL ("javascript:saveNotes()");
    }

    It all seems like it should work... but doesn't. As soon as the page is loaded comes up with an error in the corner of the browser, so perhaps something tiny that I am missing.

    Suggestions?

    Cheers,
    Shawn
    Shawn Ryder
    Auto University Vice President
    http://www.autouniversity.com
    E-mail: shawn.ryder@autouniversity.com

  2. #2
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it might help us debug if we knew the error. Also is this on a page somewhere that we can see? Perhaps that would help us debug as well. Thanks.

    Sketch
    Aaron Brazell
    Technosailor




Bookmarks

Posting Permissions

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