PDA

View Full Version : Don't replay movie on refresh of page - Going Absolutely Crazy



Runedro
August 20th, 2008, 06:21 PM
Hi, total n00b here to AS3, hopefully someone can help me.

This seems like a simple script I want to write, but for the past 2 days I can't seem to get it started...

Here's what I want to do:

I have a flash movie that I want to play once. If someone refreshes the page, I want it to check to see if it has already been viewed that day and if so, just go to the last frame of the movie instead of playing all over again.

Here's sort of a flowchart:

1. Start a flash cookie
2. Set a variable for a "check date" and "if viewed"
3. Check "if viewed" - no=play yes=checkdate
4. If checkdate = today=don't play goto last frame
newday=replay movie and set played for that day.

Make any sense?
<:\ HeLp plz?

Runedro
August 21st, 2008, 12:08 AM
Anyone??? :crazy:

Felixz
August 21st, 2008, 06:05 PM
Use SharedObject

Runedro
August 27th, 2008, 12:58 AM
This is what I've managed to come up with in the past couple of days.
Still not working. I know there's lots of mistakes. :puzzle:

Any help/comments? TIA


////////////////////////////////////
// ©2008 runedro @ gmail . com //
////////////////////////////////////
import flash.net.SharedObject;

var $so:SharedObject = SharedObject.getLocal("logoInfo"); // retrieve cookie
var $today = $today.getDate(); // set today's date
var $viewDate:Date = $so.data.$viewDate; // retrieve date last viewed
var $viewed:Boolean = $so.data.$viewed; // retrieve 'viewed' status

if ($viewed == true) {
if ($viewDate == $today) {
gotoAndStop(250);
}else{
play();
$so.data.$viewDate = $viewDate.getDate(); // set date last viewed
$so.data.$viewed = true; // set 'viewed' switch
$so.flush(); // write changes to cookie
}
}else{
play();
$so.data.$viewDate = $viewDate.getDate(); // set date last viewed
$so.data.$viewed; // set 'viewed' switch
$so.flush(); // write changes to cookie
}

Felixz
August 27th, 2008, 10:03 AM
http://www.kirupa.com/forum/showthread.php?t=279643&highlight=sharedobject

Runedro
August 28th, 2008, 11:53 AM
Ok, so now I have this:


var date=new Date();
var sharedObject:SharedObject = SharedObject.getLocal("logoReplay");
if (sharedObject.data.lastVisit && (date.time - sharedObject.data.lastVisit.time) / 1000 / 60 / 60 > 24) {
play();//when user visits site after 24 hours
}else{
gotoAndPlay(250);
}
sharedObject.data.lastVisit = date;
It still keeps replaying. I tried the original script without modification, and the "showIntro()" gives me an error.

Felixz
August 28th, 2008, 12:30 PM
Well, I have missed one detail...
Here is updated code
var date=new Date();
var sharedObject:SharedObject = SharedObject.getLocal("splash");
if (sharedObject.data.lastVisit && (date.time - sharedObject.data.lastVisit.time) / 1000 / 60 / 60 < 24) trace("skip();") else trace("play();");
sharedObject.data.lastVisit = date;

Runedro
August 28th, 2008, 11:12 PM
Sorry, man, but that's still not working.

I can't even find a function called skip(). And why do I need to trace these functions ( skip() and play() )? I also need the whole thing to go to frame 250 if it has already played and stay there. For some reason gotoAndStop(250) does not work.

I'm at a total loss. What am I doing wrong?
I'm trying man, I really am.

Felixz
August 29th, 2008, 10:11 AM
these traces were for testing purposes.

var date=new Date();
var sharedObject:SharedObject = SharedObject.getLocal("splash");
if (sharedObject.data.lastVisit && (date.time - sharedObject.data.lastVisit.time) / 1000 / 60 / 60 < 24) gotoAndPlay(250); else play();
sharedObject.data.lastVisit = date;Sorry for being confusing.

Runedro
August 29th, 2008, 11:32 AM
No need to apologize, I'm really appreciative of your help. What you had in your last post was pretty much the same as what I had going yesterday, but for some reason it isn't going to the last frame (250). Instead it seems it's going to frame 27 for some reason and continuing to play to the EOF. I'm wondering now if maybe the .fla is corrupt somehow.

I've checked the versions of my software and they are up to date. I've even used others' flash apps to see if they work, and they work fine so it can't be my flash player.

There are 6 layers in the .fla and I'm placing the AS3 script on frame 1, scene 1 on the top layer. Should placement of the script make any difference - except for when the code gets executed?

Any ideas? :-/ Really appreciate the assistance.

creatify
August 29th, 2008, 12:02 PM
are you making sure you movie is completely preloaded prior to your shared object checking? Sounds to me like the checker is find the SO, and then trying to force the movie to frame 250 before that frame has loaded.

Runedro
August 29th, 2008, 01:52 PM
Many, many thanks to you guys, Felixz and Creatify.

Got it working, smooth as silk. Put in the preloader, and it works like a charm. I got ahead of myself when I started and forgot to put one in. :-/

Again, many, many thanks! :thumb2:

Runedro
September 1st, 2008, 07:40 PM
:emb: ...I guess I spoke too soon...

Two problems have arose in the past few days...

1. The formula for the 'lastViewed' doesn't quite work right. I wanted it to replay 24hrs. after the first time it is viewed. As it is now, the formula writes the 'lastViewed' date each time it is viewed and resets the 24hr timer. Any suggestions?

2. It's only a guess, but I have narrowed the problem down to the flash object I have created. Since I've started using this flash logo, none of my youtube (or other) embedded movies play. I'm guessing there's a problem with the sharedObject in my .swf that is interfering with the browser players. Any thoughts?

Thanks again guys.

Felixz
September 2nd, 2008, 07:11 AM
var date=new Date();
var sharedObject:SharedObject = SharedObject.getLocal("splash");
if (sharedObject.data.lastVisit && (date.time - sharedObject.data.lastVisit.time) / 1000 / 60 / 60 < 24) gotoAndPlay(250) else {
play();
sharedObject.data.lastVisit = date;
}

Runedro
September 5th, 2008, 02:01 AM
:( That code, just lets it play again after every refresh... I'll try and figure something out with the formula...

The bigger problem is, why is it interfering with embedded video? I figure it's something in the AS3 code... Any thoughts?

Here is my preloader code I'm using: (which is working)


stop();

this.addEventListener(Event.ENTER_FRAME, loading);

function loading(e:Event):void{
var total:Number = this.stage.loaderInfo.bytesTotal;
var loaded:Number = this.stage.loaderInfo.bytesLoaded;

loader_txt.text = Math.floor((loaded/total)*100)+ "%";

if (total == loaded){
play();
this.removeEventListener(Event.ENTER_FRAME, loading);
}

}Anything in there that might cause a conflict?

Runedro
September 6th, 2008, 01:52 AM
... me again...

Did a bit more digging, and discovered that the embedded video problem originates with the Flash Plugin (v9.0.124.0 and other v9 flash player plugins).


Solution: I used Adobe®'s uninstaller
flashplayer10_uninstall_081108.exe (http://download.macromedia.com/pub/labs/flashplayer10/flashplayer10_uninstall_081108.exe)

to remove the old plugin and installed the Flash 10 beta -
flashplayer10_install_plugin_081108.exe (http://download.macromedia.com/pub/labs/flashplayer10/flashplayer10_install_plugin_081108.exe)

Everything seems to be back to normal again. Thanks again guys.

BTW: Felixz - I'll get back to you if I have more trouble with the formula code for checking the date. Hope you don't mind... Thx. :beam:

Runedro
September 10th, 2008, 12:53 PM
Just thought I'd let you guys know everything seems fine again... I have the script working exactly the way I want it to now! :)

Here's what I ended up with:


var date=new Date();
var sharedObject:SharedObject = SharedObject.getLocal("splash");

if (sharedObject.data.lastVisit && (date.time - sharedObject.data.lastVisit.time) / 1000 / 60 / 60 < 0.1666666666666666 ) {
gotoAndStop(251);
}else{
play();
sharedObject.data.lastVisit = date;
}

I'm hoping that that is the right formula to play the flash file every 10 minutes? 10 / 60 = 0.1666666666666667. Can someone confirm this number?

Again, thanks guys. :beer2:

Felixz
September 10th, 2008, 02:17 PM
1000 / 60 < 10

dhawal.mhatre
June 9th, 2009, 03:41 AM
ActionScript Code:

var date=new Date();
var sharedObject:SharedObject = SharedObject.getLocal("splash");
if (sharedObject.data.lastVisit && (date.time - sharedObject.data.lastVisit.time) / 1000 / 60 / 60 < 24) gotoAndPlay(250) else {
play();
sharedObject.data.lastVisit = date;
}




where to paste this code .... in preloader