A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: you probably DON'T want to answer this question

  1. #1
    Senior Member
    Join Date
    Mar 2000
    Posts
    457
    Since the answer probably involves a lot of typing.
    But then again you might want to end up in my credits page and besides that you ARE willing to help me out (again).

    Heres the question.

    On my website there is an option to choose a different background.
    Is it possible to write some cookie (that's probably how it's done)
    That remembers which background had been on when the visitor left my site.
    So that when he comes back the same background is displayed.

    I know it is possible to write a cookie when you leave a page by using this tag:
    <BODY onUnload="write it()">

    But i don't have a clue what's next

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi Michel,

    you know how to write a cookie from html / javascript?
    Just place a function in your html page like cookie(name) which writes the cookie and call it from your flash movie as
    geturl("javascript:cookie('"+bgname+"')")
    whenever the background is changed - so if the user tries all of them the cookie will be rewritten a few times

    To make reading the cookie work on all browsers, use javascript document.write() to write the entire html embedding, and let it pass the cookie value into the movie like
    embed src="movie.swf?bgname=mountains&music=...."
    Make sure you add it to movie name in object and embed parts

    Musicman

  3. #3
    Senior Member
    Join Date
    Mar 2000
    Posts
    457
    Musicman
    I am happy you are replying my post since that gives me the feeling it's solved already
    Like the write cookie to ALWAYS skip my intro
    Remember me
    http://www.flashplanet.nl

    This (again) is probably way to hard for me and making my problem yours (it's just something that came up in my head )

    I won't be dossapointed (ahum)
    If you don't have time to help me but.......

    Is there a way that you could send me an example of the HTML code that i could use?

    Thanks in advance
    Michel


  4. #4
    Senior Member
    Join Date
    Mar 2000
    Posts
    457
    btw
    each background is a seperate loaded swf file (maybe that is of some help with the coding)

  5. #5
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi Michel,

    since this might be interesting to others as well, I put the script here:
    Code:
    <head>
    <title>flash with cookies</title>
    <script>
    var cstring = document.cookie;
    if(cstring != '')
    {       cstring = '?' + cstring;
            while((l = cstring.indexOf(';')) > 0)
                    cstring = cstring.substr(0, l) + '&' + cstring.substr(l+2, cstring.length-l-1);
    }
    function setcookie(str, val)
    {       var expiredate=new Date();
            expiredate.setDate(365+expiredate.getDate());
            document.cookie = str+'='+escape(val)+';path=/;expires='+expiredate.toGMTString()+';';
    }
    </script>
    </head>
    <body bgcolor=silver>
    <script>
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" width="640" height="480">'+
    '<param name="movie" value="movie.swf'+cstring+'">'+
    '<param name="quality" value="best">'+
    '<param name="play" value="true">'+
    '<embed src="movie.swf'+cstring+'" type="application/x-shockwave-flash" width="640" height="480" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" quality="best" play="true">'+
    '</object>');
    </script>
    There are three parts to it:
    when the page loads, the cookie is retrieved and reformatted by adding ? at the beginning and replacing ; with & in case there are multiple cookies
    a function setcookie which is called with two args, say 'backgound' or 'music' and the name of the corresponding swf file. You call this function from your movie whenever one of these persistent variables is changed
    a html embedding written by javascript which puts the reformatted cookie variable on the end of the movie name. Use the html embedding flash generates for your movie and change it in a similar manner

    Musicman
    [Edited by Musicman on 06-16-2001 at 01:34 PM]

  6. #6
    Senior Member
    Join Date
    Mar 2000
    Posts
    457

    Smile

    Hi there Musicman.......

    One last question
    In this situation does it matter which names the background files have?
    Or do i need to place specific code into each background.swf file in order to write this cookie?

    Like i told you i am not fully aware of this cookie stuf
    Reading the code above doesn't really ring a bel

    So could you please specify how to combine this code with the background files?

    Or should i actionscript the buttons that need to be clicked in order to change the backgrounds?

    Hope you've got time for this.

    Thanks in advance
    Stan (your biggest fan )

    p.s.
    I did a copy and paste of the code above
    and used some swf file that i renamed movie.swf and copied that into the same folder as the html page containing this code) It might be that i did something wrong but......
    It doesn't load the movie and the statusbar of my IE tells me there is a script error).


    [Edited by Michel on 06-16-2001 at 02:57 AM]

  7. #7
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi Michel,

    it seems that 2 lines in the embedding got truncated; they should all end with >'+
    You should use a html published for your movie anyway, so all the settings are in the right place, and just add the document.write(' and ' etc. bits.
    Now the idea is that the button which selects a new background would do a
    geturl('javascript:setcookie("background","mountai n.swf")')
    If you make other things configurable as well, you could use the same code again.
    When your movie starts, it will have variable background defined from the cookie - otherwise set it to initial value and call cookie function for the first time

    Musicman

  8. #8
    Senior Member
    Join Date
    Mar 2000
    Posts
    457

    Still getting the javascript error :o(

    I get the picture that is i know how to handle the flash part
    i somehow can't figure out what the exact html code lines should be
    could you please copy and paste the code in the thread again?

  9. #9
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi Michel,

    changed it...
    Let me know your email, this saves a lot of silly cutting and pasting

    Musicman

  10. #10
    Senior Member
    Join Date
    Mar 2000
    Posts
    457

    sorry for the late reply :o(

    Thanks for all the effort
    and your time.

    here's my e-mail address:
    m.staal@chello.nl

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center