I understand what you are saying. But this cookie syntax is correct. It works perfectly on its own. The only time it doesnt work is with swfObject embed. Thats been the problem from the start. The code Ive pasted below is the extact code I have been using all along except it uses a conditional statement and document.write rather than attempting to interact with a SWF via swfObject flashvars. If you test the following code, you will see that the cookie does work. I just need a way to communicate the value to Flash.
Thanks man, I'll send you a 6-pack of whatever you want. Promise. 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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <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") else document.write("Thank you for returning for what appears to be your visit number " + visits + ".") // --> </SCRIPT> </body> </html> On Dec 31 2009, 12:48 pm, Philip Hutchison <[email protected]> wrote: > Ryan > > My point is that your getCookie JavaScript function must not be returning a > proper value. If the SWFObject embed code works with a static value, then we > know SWFObject works and your SWF loads correctly. If it doesn't work when > your getCookie function is used, it's most likely because your getCookie > function isn't returning a proper value. You can't pass *null* as a > flashvars value because null is the *absence* of value. > > var flashvars = { visits: null }; > > will cause SWFObject to out this as a flashvar: > > "visits="+null > > Which will not work. If you change your getCookie function to return an > empty string instead of null when no cookie is found, you will be better off > > var flashvars = { visits: "" }; > > will cause SWFObject to out this as a flashvar: > > "visits="+"" > > This is a harmless statement that won't throw any errors. > > Or, as I previously mentioned, if you use an || operator in your flashvars > statement you can leave your getCookie function as-is: > > var flashvars = { > visits: getCookie() || 1 > > }; > > This means if getCookie returns null, visits will be assigned a value of 1 > instead. > > Long story short, the issue is in your JS, not SWFObject. > > - philip > > > > On Thu, Dec 31, 2009 at 8:45 AM, ryan <[email protected]> wrote: > > This change did cause the swf to finally show, but I dont think it is > > a workable solution because the value of 'counter' is not static. In > > other words, if I understand this correctly, writing - var flashvars = > > { visits: 3 }; would be assigning an absolute value, which would > > defeat the purpose of having a cookie which counts. Is this not > > correct? > > > On Dec 30, 4:59 pm, Philip Hutchison <[email protected]> wrote: > > > If your SWFObject embed code works when you don't specify the flashvars: > > > > swfobject.embedSWF("main_banner.swf", "myContent", "189", "151", "9.0.0", > > > false); > > > > and fails when you DO use the flashvars: > > > > var flashvars= { visits: getCookie('counter') }; > > > swfobject.embedSWF("main_banner.swf", "myContent", "189", "151", "9.0.0", > > > false, flashvars); > > > > then logic dictates that there's a problem with your flashvars value. > > try > > > using a static value instead of the getCookie function. > > > > var flashvars = { visits: 3 }; > > > swfobject.embedSWF("main_banner.swf", "myContent", "189", "151", "9.0.0", > > > false, flashvars); > > > > make sure you use the SAME HTML PAGE for each test so you can eliminate > > any > > > other potential conflicts. > > > > - philip > > > > On Wed, Dec 30, 2009 at 11:03 AM, ryan <[email protected]> > > wrote: > > > > The swfobject is still returning the alternate content. The cookie > > > > works fine independantly. > > > > > see below: > > > > > <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 your first visit") > > > > else > > > > document.write("Thank you for returning for your visit number " + > > > > visits + " " ) > > > > > // --> > > > > > I have had no probelm getting this to register whatever the visit > > > > number is. I just need to pass that number on to Flash. Thanks again > > > > man, you are a trooper. > > > > > Ry > > > > > On Dec 30, 1:13 pm, Philip Hutchison <[email protected]> wrote: > > > > > i meant you're testing for a number: > > > > > > visit == 1 > > > > > > but passing a string via flashvars. > > > > > > trace(_root.visit === "1"); > > > > > trace(_root.visit === 1); > > > > > > if you want to look for a number in your conditional statements, you > > > > should > > > > > convert the string to a proper number. > > > > > > your swfobject code looks ok. i see your getcookie function is a bit > > > > > complex and could possibly return a null. a null flashvars value > > could > > > > cause > > > > > an error in swfobject. try changing the flashvars to this and see if > > it > > > > > works: > > > > > > var flashvars= { > > > > > visits: getCookie('counter') || 1 > > > > > > }; > > > > > > this way if getcookie has problems you'll pass a 1 instead. > > > > > > - philip > > > > > > On Wed, Dec 30, 2009 at 9:30 AM, ryan <[email protected]> > > > > wrote: > > > > > > Hi Philip, > > > > > > Thanks again, but I am still getting the same result. Im not sure > > what > > > > > > the problem is, but this is the embed tag as I have it now. I took > > > > > > your advice and ammended visits to capvisits- but I need to make it > > to > > > > > > a point where the swf is showing up in order to test that. In your > > > > > > reply you mentioned casting the numbers in the string, do you mean > > > > > > declaring var visits:String = "1,2,3,4"? and if so, would I place > > that > > > > > > in the Flash file or the javascript? > > > > > > > Thanks for all your help on this, > > > > > > Ryan > > > > > > > <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", false, flashvars); > > > > > > </script> > > > > > > </head> > > > > > > > On Dec 30, 11:53 am, Philip Hutchison <[email protected]> > > wrote: > > > > > > > Your SWFObject statement is malformed. Sorry I didn't notice that > > > > > > earlier. > > > > > > > > This: > > > > > > > swfobject.embedSWF("main_banner.swf", "myContent", "189", > > > > "151","9.0.0", > > > > > > > flashvars); > > > > > > > > Should be this: > > > > > > > swfobject.embedSWF("main_banner.swf", "myContent", "189", > > > > "151","9.0.0", > > > > > > > false, flashvars); > > > > > > > > (You're missing the required Express Install argument before the > > > > > > flashvars > > > > > > > argument) > > > > > > > > Here are some other thoughts: > > > > > > > > * You might want to look at how the data is being passed to the > > > > SWF... > > > > > > > values passed via flashvars are all strings. Your SWF's > > conditional > > > > > > > statements are looking for numbers. Maybe you need to cast them. > > > > > > > > * Your "visits" variable is listed as _root.visit in one place > > but > > > > simply > > > > > > as > > > > > > > "visit" in another. Perhaps there's a scope issue because of > > this? > > > > > > > > * Are your "visits" conditional statements supposed to be using > > > > > > "capvisits"? > > > > > > > > Here's what I assume you're trying to do: > > > > > > > > var capvisits:Number = Number(_root.visits) || 1; > > > > > > > > if (capvisits == 1) { > > > > > > > this.gotoAndPlay("investment_focus"); > > > > > > > > } > > > > > > > > if (capvisits == 2) { > > > > > > > this.gotoAndPlay("white_papers"); > > > > > > > > } > > > > > > > > - philip > > > > > > > > On Wed, Dec 30, 2009 at 8:39 AM, ryan < > > [email protected]> > > > > > > wrote: > > > > > > > > Hi Philip, > > > > > > > > Thanks for your reply. I made the code change you suggested and > > > > > > > > unfortunately I am getting the same result (the alternative > > content > > > > > > > > displays). I feel like this is really close though. If anyone > > has a > > > > > > > > little extra insight I would love it and thanks again Philip. > > > > > > > > Ryan > > > > > > > > > On Dec 30, 11:28 am, Philip Hutchison <[email protected]> > > > > wrote: > > > > > > > > > this: > > > > > > > > > var flashvars = {"visits=' + getCookie('counter')+'"}; > > > > > > > > > > should be this: > > > > > > > > > var flashvars = { visits: getCookie('counter') }; > > > > > > > > > > - philip > > > > > > > > > > On Wed, Dec 30, 2009 at 7:51 AM, ryan < > > > > [email protected]> > > > > > > > > wrote: > > > > > > > > > > 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 > > ... > > read more »- Hide quoted text - > > - Show quoted text - -- 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.
