A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: A save feature..... How?

  1. #1
    hi,
    i am making a game for the internet, and i wanted to add a save feature. whats the best way to do this.

    can any1 help?

    thanx
    Gadgets

  2. #2
    Senior Member Olorin's Avatar
    Join Date
    Aug 2000
    Posts
    1,151
    there are 2 ways to do it:

    1) use php, asp or cgi to save a file or database entry to the server.

    2) use cookies to save it on the client computer.


    Olorin

  3. #3
    How would you use cookies to save,would I have to put in the html, i'm interested in this subject too.

  4. #4
    Senior Member Olorin's Avatar
    Join Date
    Aug 2000
    Posts
    1,151
    Cookies can be done in two ways, either through php/cgi, or though javascripting.
    If you use javascript, you put the javascript in the html page which holds the swf. Make sure the whole thing is a function, so you can call it with the "Get Url" command in flash (make sure "send variables" is checked).
    If you use php or cgi for cookies, just send the variables to the script with "Get Url"

    Olorin

  5. #5
    Junior Member
    Join Date
    Dec 2000
    Posts
    16
    hi
    What Javascript would u have to us????? U no the Code???

    Flash-ZeRo

  6. #6
    Senior Member Olorin's Avatar
    Join Date
    Aug 2000
    Posts
    1,151
    It's a whole big bunch of code :

    Code:
    <!-- write cookie // -->
    
    <script language="JavaScript">
    
    function SetCookie (name, value) {
             var argv = SetCookie.arguments;
             var argc = SetCookie.arguments.length;
             var expires = (argc > 2) ? argv[2] : null;
             var path = (argc > 3) ? argv[3] : null;
             var domain = (argc > 4) ? argv[4] : null;
             var secure = (argc > 5) ? argv[5] : false;
             document.cookie = name + "=" + escape (value) +
             ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
             ((path == null) ? "" : ("; path=" + path)) +
             ((domain == null) ? "" : ("; domain=" + domain)) +
             ((secure == true) ? "; secure" : "");
    }
    
    
    function cookiepower()
    {
    
    var expdate = new Date ();
    expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
    
    SetCookie('zcompany', cooky.company.value, expdate); 
    SetCookie('zcontactperson', cooky.contactperson.value, expdate); 
    SetCookie('zaddress', cooky.address.value, expdate); 
    SetCookie('zzip', cooky.zip.value, expdate); 
    SetCookie('zcity', cooky.city.value, expdate); 
    SetCookie('zcountry', cooky.country.value, expdate); 
    SetCookie('zphone', cooky.phone.value, expdate); 
    SetCookie('zfax', cooky.fax.value, expdate); 
    SetCookie('zemail', cooky.emailaddress.value, expdate);
    SetCookie('zjob_title', cooky.job_title.value, expdate);
    
    </script>
    
    
    
    
    <!-- read cookie // -->
    
    
    <script language="JavaScript">
    
    function getCookieVal (offset) {
    	  var endstr = document.cookie.indexOf (";", offset);
    	  if (endstr == -1)
    		endstr = document.cookie.length;
    	  return unescape(document.cookie.substring(offset, endstr));
    	}
    
    function GetCookie (name) {
    	  var arg = name + "=";
    	  var alen = arg.length;
    	  var clen = document.cookie.length;
    	  var i = 0;
    	  while (i < clen) {
    		var j = i + alen;
    		if (document.cookie.substring(i, j) == arg)
    		  return getCookieVal (j);
    		i = document.cookie.indexOf(" ", i) + 1;
    		if (i == 0) break; 
    	  }
    	  return null;
    	}
    
    
    function doitnow()
    {
    var zcompany=GetCookie("zcompany")
    var zcontactperson=GetCookie("zcontactperson")
    var zaddress=GetCookie("zaddress")
    var zzip=GetCookie("zzip")
    var zcity=GetCookie("zcity")
    var zcountry=GetCookie("zcountry")
    var zphone=GetCookie("zphone")
    var zfax=GetCookie("zfax")
    var zemail=GetCookie("zemail")
    var zjob_title=GetCookie("zjob_title")
    }
    
    </script>


    you'll have to change some variables to get it to work for your game. Basically I've used the function "cookiepower()" to write a whole bunch of cookies (set to last a year) and the function "doitnow()" to read the cookie and place it in variables.

    The SetCookie() function is set up in a way here that it retrieves a variable from an html form called "cooky" but you should change it that it gets the variables from the flash movie.

    (I've never tried combining this code with flash... but it should work)

    Good luck,

    Olorin

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