Tuesday, June 23, 2009

Setting and Reading Cookies in Flash AS2

View the actionscript 3 version of this post
Setting a cookie with Flash (Actionscript 2.0) is really easy. Reading that cookie in Flash (or passing the value of the cookie back into flash) isn't so easy (well, at least that's what the internet would have you believe). After searching for some documentation on the matter without any luck, I took matters into my own hands. It turns out if you use the jquery library, it is actually pretty easy.

First of all, you need to make sure you are using SWFobject to embed your flash, like this example: (make sure you have the swfobject js file included in your head)
<div id="flashcontent">Alt Content Goes Here</div>
<p><script type="text/javascript"> var so = new SWFObject("HomePageFlash.swf", "mymovie", "573", "434", "9", "#f0af2c");
  so.addParam("quality", "high");
  so.addParam("wmode", "transparent");

Then you need jquery installed.
And you also need the jquery cookie plugin included.

To set a cookie from flash you just need to call a js function that is in the cookie plugin thusly:
getURL("javascript:$.cookie('flash_cookie', 'the_value')");
You can add as many params as you need thisly:
getURL("javascript:$.cookie('flash_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true })");

Now for the exciting part. If you want to read that cookie in flash, all you need to do is pass it in using addVariables. In the SWFobject, just add this line of code BEFORE it writes the flash (so before the so.write part in my example):

  so.addVariable("theCookie", $.cookie('flash_cookie'));

('theCookie' being a variable that will be passed into flash and the $.cookie part will pull the value of that cookie and dump it into 'theCookie')

If you have questions, feel free to comment.

(issues: Setting cookies in flash, reading cookies with flash, passing cookies into flash, as2, actionscript2, flash 8, pass cookies with addVariables, pass cookies with SWFobject)

Monday, April 21, 2008

Gradient on Dynamic Text

text_mc.myText_txt.text ="this text has a gradient";

Put 'mask_mc' (which is a box with a gradient) on the layer under text_mc.

Kerning Dynamic Text

var fmt:TextFormat = new TextFormat();
fmt.letterSpacing = 3;

myText_txt.text = "THIS TEXT NEEDS TO KERN";

Tuesday, April 15, 2008

The Super Gallery

I combined the two previous galleries I've posted and made one super gallery.

Take a look at it

This gallery is driven 100% from xml.

Download Filezzzz

Wednesday, April 9, 2008

Flash Shared Object (aka Flash Cookies)

This will enable you to create a variable and have flash remember it when the page is reloaded. You can even do it across multiple swfs. This code is for a flash scavenger hunt I made, where I had to keep track of which easter eggs had been found, and which easter egg to point the user to next. It also has to be able to know when all 3 have been found:

the_so=SharedObject.getLocal("scavenger","/"); //the "/" makes it so it works across multiple swf's
// set the new variables to 0 by default
if (the_so.data._sumoTask == undefined) {
the_so.flush; //this saves the shared object immediately as opposed to when the swf shuts down
if (the_so.data._computerTask == undefined) {

if (the_so.data._vanTask == undefined) {

//The following sets up variables to match the shared object variables
sumoTask = the_so.data._sumoTask;
computerTask = the_so.data._computerTask;
vanTask = the_so.data._vanTask;

vanMorph_mc.button_btn.onRelease = function(){
the_so.data._vanTask = 1; //sets this so variable to 1. now when you come back or go to another task, it knows this task has already been completed.

clear_btn.onRelease = function(){
the_so.clear(); //This will clear the cookies

You can make any variable you want to remember a number of different things...such as scores, backgrounds (if you have multiple bg, you can remember which one the user had selected), etc.

Friday, December 7, 2007

Dynamic Expandable Menu


This is a pretty rockin' expandable menu I made for the good men at Agency Fusion. The coolest part about this is that it is COMPLETELY DYNAMIC! (well, the sub-nav anyway). All you have to do is update an XML file and your menu is changed. Once the menu gets longer than 4 links, it becomes scrollable. holla!

download files: [CLICK HERE]

Here's what's even cooler. Agency fusion has this nav plugged into a CMS. All the client needs to do to update is create a new page in the CMS and it automatically updates the xml...which updates the flash. Pretty slick!! Here is how it was implemented: www.odysseyrealestatecapital.com