Thanks in advance for looking at this. I am trying to set/ retrieve a
cookie which counts a users visits to a page and then returns the
value using flashvars and swfobject2. The cookie and the swf work
independantly, the swfobject embed works fine until i try to ad the
vars... The examples I dowloaded all use a conditional statement to
apphend the vars in the html file itself. I have code within the root
of my swf telling the file what to do with the cookie. IE;
var capvisits:String = _root.visits;
if (capvisits == null) {
capvisits = 1;
}
if (visits == 1) {
this.gotoAndPlay("investment_focus");
}
if (visits == 2) {
this.gotoAndPlay("white_papers");
}
etc. - but if it would be better to write this into the flashvars I am
perfectly open to that as well. Following is the entire file. Thanks
again, Ryan
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/
libs/swfobject/2.2/swfobject.js"></script>
<script type="text/javascript">
var flashvars = {"visits=' + getCookie('counter')+'"};
swfobject.embedSWF("main_banner.swf", "myContent", "189", "151",
"9.0.0", flashvars);
</script>
</head>
<body>
<div id="myContent">
<h1>Alternative content</h1>
<p><a href="http://www.adobe.com/go/getflashplayer"><img
src="http://www.adobe.com/images/shared/download_buttons/
get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
</div>
</body>
<SCRIPT LANGUAGE="JavaScript">
<!--
// Boolean variable specified if alert should be displayed if cookie
exceeds 4KB
var caution = false
function setCookie( jscookie, value, expires, path, domain, secure) {
var curCookie = jscookie + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() :
"") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "")
if (!caution || (name + "=" + escape(value)).length <= 4000)
document.cookie = curCookie
else
if (confirm("Cookie exceeds 4KB and will be cut!"))
document.cookie = curCookie
}
// name - name of the desired cookie
// * return string containing value of specified cookie or null if
cookie does not exist
function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";",
cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex +
prefix.length, cookieEndIndex))
}
// date - any instance of the Date object
// * you should hand all instances of the Date object to this function
for "repairs"
// * this function is taken from Chapter 14, "Time and Date in
JavaScript", in "Learn Advanced JavaScript Programming"
function fixDate(date) {
var base = new Date(0)
var skew = base.getTime()
if (skew > 0)
date.setTime(date.getTime() - skew)
}
var now = new Date()
fixDate(now)
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000)
var visits = getCookie("counter")
if (!visits)
visits = 1
else
visits = parseInt(visits) + 1
setCookie("counter", visits, now)
//if (visits == 1)
//document.write("Thank you for what appears to be your first visit to
the Curious Cat Cookie Center")
//else
//document.write("Thank you for returning for what appears to be your
visit number " + visits + " to the Curious Cat Cookie Center." )
// -->
</body>
</html>
--
You received this message because you are subscribed to the Google Groups
"SWFObject" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/swfobject?hl=en.