If you want to write some data on visitor's of your page HDD, it is enough
to put in HTML code something like
<script>
document.cookie= 'anystring' + '; expires=Mon, 7 Feb 2000 23:19:15 UTC'
</script>
after it you will be able to read that "anystring" string without
quotes from that file later, but only from same url and folder (it is default
values, but you can change it by adding that params declaration in "set
cookie" script) and not after expiration time. "expires" time
part is very important. It must be exactly as in example and only in GMT (UTC)
format. So, for example, if you want to set cookie for 10 seconds (10000 msec),
you may use something like that Java script
<script>
// everything after two slash lines is comment
howlong=new Date(); //
Setting "howlong" variable to current time
howlong.setTime(howlong.getTime() + 10000); //adding
10 sec to "howlong"
howlong.toGMTString(); //
translating "howlong" to GMT format
</script>
However you may write all that strings in one string like it
<script> howlong = new Date(); howlong.setTime(howlong.getTime() + 10000); document.cookie = 'anystring' + '; expires=' + howlong.toGMTString(); <script>
As you know, it is possible to call Java Script from Flash movie directly,
without adding something in html source. But there is two big BUT here:
1. You can't call Java Script from .swf file opened in browser - it is possible
only when .html file, with .swf in it, opened in browser.
2. To make it work in Netscape, you must declare NAME
statement inside <ebbed... tag. Even the latest
MM templates don't have something like "NAME"
... MM people prefer to use different stupid things like
FS Commands or document.embeds
He-He :) Sorry - I don't want to hurt somebody :)
So, the only thing that you have to add in HTML source to make that example
work in NN is NAME and swLiveConnect="true"
statements inside <ebbed... tag. For example
if you have ID=cook , you must add NAME="cook"
If you want, you may take Flash + JavaScript template from
here - it will add NAME after every Publish
action from Flash.
There is one more little "but" here -
You can't use as "ID" and "NAME"
Java Script reserved words
like "document", "cookie",
"var" and etc.
After it you may say from Flash
Get URL ("JavaScript:howlong = new Date(); howlong.setTime(howlong.getTime() + 10000); document.cookie = 'anystring' + '; expires=' + howlong.toGMTString(); void(0);")
And void(0); part is very important too - without
it page content may change in some browsers to blank page with just "[object]"
sting on it.
Ok. At last we know how to write any string of symbols on HDD of your visitor.
Now lets try to read that string from Flash.
There is one more Java Script action "SetVariable"
you can read more about it here
http://www.macromedia.com/support/flash/publishexport/scriptingwithflash4/scriptingwithflash4.html
With this action it is possible to send Java variables to Flash. And it will
work without editing HTML code too :) If you say from Flash something like
Get URL ("javascript:document.cook.SetVariable('in_cookie',(document.cookie) ? document.cookie : '');")
It will store cookie string in Flash variable with name "in_cookie". Lets look at that action more closely :)
document.cook.SetVariable('in_cookie'
part mean that Java variable will be send to "in_cookie"
variable inside flash movie with ID=cook (and
NAME="cook" as well :) on current page
(document).
And
(document.cookie) ? document.cookie : ''
defines what java variable will be send to flash
and it mean something like
if -> ?
cookie exist and valid -> (document.cookie) ?
variable will be equate to document.cookie value -> (document.cookie)
? document.cookie
and else -> :
it will be equate to blank string -> : ''
where '' is 2 single quotes.
As you can see after changing ID and NAME,
you have to change actions for "Read" button.
Now lets look at "Clear" button. There is two ways to remove cookie
- null its value or setting expiration time to past. "Clear" button
just use second way :)
We are still talking about only one 'anystring'
string cookie value. But in our example there is variable and 2 value. How
can it be ? Never mind :) It is still one string cookie, but I am using here
"=" symbol to separate variables and values. For example
var=val
I hope that it is clear enough to explain it :) Separation manipulations are
in "Read" button actions list.
The only thing left.
As you see Get Url Action window is in "variable" mode. In that
mode it is possible to include Flash variables in Get Url string. For example
we have Flash variable "name1" with
value "somevar" and "val1"
with value "something", than
action
"document.cookie = 'anystring' + '; expires='
+ howlong.toGMTString();"
will write anystring as cookie
string and
"document.cookie = '"&name1&"="&val1&";
expires=' + howlong.toGMTString();"
will write somevar=something as cookie
string.
It is end here :) If you still have questions, ask me using www@ok.ru
:)
![]()