Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


The Bolts

July 5, 2000

So how does this cookie get set in the first place? There is nothing in the page to set the flashCookie function in motion. We find the answer here:

//pass commands, args from Flash to JavaScript

  function flashfile_DoFSCommand(command, args) 
  
  { 
  
  if ( command == "read" ) {flashReadCookie();}
  
  else if (command == "cookie"){flashCookie(args)}
  
  else {alert("Sorry, dude - you screwed up.")}
  
  } 

The syntax for this function is strict:

  • The function must be called (Flash Player object name)_DoFSCommand().
  • Arguments are optional. You get your choice of 0, 1, or 2 arguments.(3)

Inside the Flash movie, the user arrives at frame 9, "options", (either because we send him there in our FlashReadCookie function or because he chooses "options" in frame 5). At this point we give him a clean slate on 3 of the 4 variables the cookie holds by using these actions in the main timeline:

 
Set Variable: "/:entertainment" = "off"

        Set Variable: "/:sports" = "off" 
		
        Set Variable: "/:headlines" = "off" 
	

Note that it would be a lot better to read the current value of each of the variables and assign the check boxes a value accordingly; but there is a good movie coming on TV in a while and I don't want to risk missing it in favor of smart, tidy code, (you are really getting your money's worth)!

Okay, the user sets his variables and is ready to commit to storing our cookie on his machine. He clicks submit:

 
On (Release)

        FS Command ("cookie", "entertainment:" & entertainment & "|sports:" & 
        sports & "|headlines:" & headlines & "|background:" & background & "|") 

        End On 
	

Important observations:

  • The action "FS Command.." calls our flashfile_DoFSCommand(command, args) function.
  • The top box in the Flash authoring tool (labeled "Command" is the first argument and the bottom box is the second argument).
  • The stuff in the Arguments box forms a long string that will become our cookie. It might look like this: entertainment:on|sports:on|headlines:off| (This stuff must be evaluated as an expression - that's why the equals sign).

So now our user, Valued Customer #239827347, has chosen the options he wants and started the cookie process in motion. As you can see from the following logic, the function FlashCookie takes the arguments passed from the flash movie:

else if (command == "cookie"){flashCookie(args)}

There is a simpler world inside the flashCookie function - just the argument that originated in the flash movie and the user-defined variables from way up at the top of the page...

//set cookie to value from Flash movie

        function flashCookie(flashInput)
		
        {
		
        cookieValue = flashInput;
		
        setCookie(cookieName, cookieValue, retiresAt); 
		
        }
	
//Write the cookie 

        function setCookie (name, value, retiresAt) {
		
        var expiry = retiresAt.toGMTString();
		
        document.cookie = name + '=' + escape(value) + ';expires=' + expiry; // 
        Set the cookie, adding any parameters that were specified.
		
        flashReadCookie();
		
        }
	

..and setCookie is standard fare, (assuming our site is one DNS with one directory). At the end of this function we call our old friend flashReadCookie. The whole thing starts over; but this time the user has a cookie.

Macabre Machinery
Bride of Flashenstein
What Do the Tesla Coils Do?


Up to => Home / Authoring / Flash / Flashenstein




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers