is it possible to value store cookies in Flash or Flex?

前端 未结 3 1997
你的背包
你的背包 2021-01-03 09:47

In PHP there is a setcookie function based to store it. In Flash is it possible ?. If it is possible then how? I want to store value.

3条回答
  •  粉色の甜心
    2021-01-03 10:07

    for an actual code example:

    
    import flash.net.SharedObject;
    
    // get/create the shared object with a unique name.
    // If the shared object exists this grab it, if not
    // then it will create a new one
    var so: SharedObject = SharedObject.getLocal("UniqueName");
    
    // the shared object has a propery named data, it's
    // an object on which you can create, read, or modify
    // properties (you can't set the data property itself!)
    // you can check to see if it already has something set
    // using hasOwnProperty, so we'll check if it has a var
    // use it if it does, or set it to a default if it doesn't
    if (so.data.hasOwnProperty("theProp"))
    {
        trace("already has data! It reads: " + so.data.theProp);
    }
    else
    {
        so.data.theProp = "default value";
        so.flush(); // flush saves the data
        trace("It didn't have a value, so we set it.");
    }
    

    Paste this in flash, publish it twice and see how it stored the data :)

提交回复
热议问题