PDA

View Full Version : Flash 5 alternative to shared objects?


carlhusic
01-26-2003, 03:09 AM
I just read the post from asadowsky
concerning not having a movie start at
the beginning when the viewer comes
back to it with the BACK button, or
something similar. The solution
presented was to use shared objects.
However, this seems to be an MX
solution and I'm stuck in Flash 5 until
I find another job and can afford the
upgrade.

Anyone know how to do this with good
ole' Flash 5? How about cookies - is
there a way to use them in Flash 5?
Or is there a way to pass something
like a parameter or CL arg to the
movie?

jimburton
01-26-2003, 02:16 PM
yes, use javascript or server side code to set and read cookies and pass the value of the cookie to flash either via a seperate page and loadvariables or just by writing it to the src tag of the flash object in the page.

carlhusic
01-26-2003, 08:17 PM
any chance you could point me to an
example?

jimburton
01-27-2003, 07:53 AM
do you want to use javascript (more fiddly) or do you have access to something like php, asp, coldfusion?

carlhusic
01-27-2003, 12:46 PM
I'd like to stay in Javascript. Although I'm fairly conversant in
ASP I'd like to keep it server independent - also avoid the
additional round trip to the server.

Basically I have an intro movie that takes about 15 seconds to
play (after loading is complete). On the last frames there are
some links that go to other parts of my site

When the user navigates back to that page I'd like it do jump to
the last frame so the finished movie graphics and links show
without going through the whole movie again.

I tried working with _framesloaded, _framestotal,
getFramesLoaded(), etc but didn't get the results I wanted.

I know that Flash and Javascript can communicate with each
other - I just haven't had time to plow through the book on how
to do that - I assume that at the end of the movie I could have
the Flash do something that sets a Javascript variable indicating
the movie has run at least once, and then have the Flash movie
check that variable in the preloader part and jump to the end if
it is set?

you mentioned something about writing to the SRC tag of the
movie - what's that all about?

BTW my site is at http://www.three-seasons.com

Regrds,
Carl

jimburton
01-27-2003, 01:31 PM
this method will not work on older versions of netscape and not for some set ups on a mac

make sure your movie has the name and ID attributes in the embed and object tags - this means you're able to refer to the movie as part of the DOM in javascript...

your javascript to get and set the cookie would look like this:

<script language="Javascript">
function getSetCookie() {
if(document.cookie.length > 0) {
document.movie.SetVariable("cookie","skip");
} else {
document.movie.SetVariable("cookie","play");
document.cookie = "beenHereBefore:true";
}
}

</script>


then call this function from within flash with the line:

getURL("javascript:void(0);getSetCookie();");


this way you can be sure that the movie is loaded...then you need to pick up the value returned so you need something like this:

//site there on frame 1 until data comes back from javascript...
stop();
_root.onEnterFrame = function() {
if(this.cookie == "play") {
this.gotoAndPlay("intro");
this.onEnterFrame = undefined;
} else if (this.cookie == "skip") {
this.gotoAndPlay("skipIntro");
this.onEnterFrame = undefined;
}
}


the thing I said about sticking the variable on the end of the src attribute would be the serverside way to do it - less code...in the html that looks like this :
<PARAM NAME=movie VALUE="cookie_skip_intro.swf">

you can go

<PARAM NAME=movie VALUE="cookie_skip_intro.swf?data=<% some asp %>">

then the var *data* is available on main timeline. this also has advantage that it's available for all clients.

jimburton
01-27-2003, 01:34 PM
something to note is that if you have other cookies stored or someone else on same domain is using them, you will have to break down the cookie and look for the one specific to this page...see http://javascript.internet.com/ for lots of cookie scripts

also, there is a javascript method to send the movie to a particular frame, which would do away with the need for the onEnterFrame function...see http://www.macromedia.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_03.html

jimburton
01-27-2003, 01:39 PM
sorry, just realised you're on f5...put that onEnterFrame function on a clip, ie:


onClipEvent(enterFrame) {
if(_parent.cookie == "play") {
parent.gotoAndPlay("intro");
} else if (parent.cookie == "skip") {
parent.gotoAndPlay("skipIntro");
}
}