A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: swf header to play once per visit

  1. #1
    Member
    Join Date
    Jul 2005
    Posts
    49

    swf header to play once per visit

    Well, I have done some searching to try and find a way to do this, but I have not found much info on this and wanted to know if anyone on here may know of a solution to this. I have created a swf header and the client now wants it to play only once per visit to the site. Is this possible and if so, has anybody seen any tutorials or any simple scripts that can be added to make this happen?

  2. #2
    Junior Member
    Join Date
    Mar 2008
    Posts
    9
    yes you can do this... Look in to SharedObjects() its like a flash cookie.

  3. #3
    Member
    Join Date
    Jul 2005
    Posts
    49
    Thanks for the info rwatts. Now I found the code below after doing the search for shared objects, but I am a novice when it comes to AS. My intro has my Preloader on frame1 and my content starts on frame 2 which is a single MC, but where would I put this code and does my MC have to be named a shared object or do I need to attach a Shared object name to the MC.


    onLoad () {
    //This code gets todays date from the PC Clock
    mydate = new date();
    myDay = mydate.getdate();
    }
    onFrame (1) {
    //this code checks if the visitor has already
    //seen this swf today.
    so = sharedobject.getlocal("lastvisit");

    //if they have, it takes them to frame 541
    if (so.data.date==myDay) {
    gotoAndPlay(541);
    }
    }
    onFrame (541) {

    //This code writes or rewrites the cookie with todays date
    so = sharedobject.getlocal("lastvisit");
    so.data.date=myDay;
    so.flush();
    }

  4. #4
    Senior Member
    Join Date
    Oct 2004
    Posts
    2,049
    PHP Code:
    // in your content ( MovieClip ) on frame 1 put a stop();


    // this is your root time line
    onLoad () {
        
    //This code gets todays date from the PC Clock
        
    mydate = new date();
        
    myDay mydate.getdate();
    }

    onFrame (1) {
        
    so sharedobject.getlocal("lastvisit");
        
        if (
    so.data.date==myDay) {
             
    // content.gotoAndStop(); // last frame of your content movieclip
        
    }else{
            
    //This code writes or rewrites the cookie with todays date
            
    so sharedobject.getlocal("lastvisit");
            
    so.data.date=myDay;
            
    so.flush();
            
    content.gotoAndPlay(2);
        }


  5. #5
    Member
    Join Date
    Jul 2005
    Posts
    49
    Ok, so inside my MC which is called intro and has been placed on the main timeline, I need to put a stop inside that MC or on the root timeline? Reason I ask is because if I put a stop on frame 1 won't that make it so the Intro MC will not start playing. Also I see you put content.gotoAndStop after the if command. Would content be my ontro MC and do I need to give it an instance name? Sorry for all the questions, the shared object scripting is just very new to me

  6. #6
    Senior Member
    Join Date
    Oct 2004
    Posts
    2,049
    ooops sorry Tempest. Try this out.

    PHP Code:
    onLoad () {
        
    //This code gets todays date from the PC Clock
        
    mydate = new date();
        
    myDay mydate.getdate();
    }

    onFrame (1) {
        
    so sharedobject.getlocal("lastvisit");
        
        if (
    so.data.date==myDay) {
             
    // # = whatever is the last frame of your intro movieclip
             
    intro.gotoAndStop(#); 
        
    }else{
            
    //This code writes or rewrites the cookie with todays date
           // and plays the banner
            
    so sharedobject.getlocal("lastvisit");
            
    so.data.date=myDay;
            
    so.flush();
        }


  7. #7
    Member
    Join Date
    Jul 2005
    Posts
    49
    Hi wattsup, well I placed the changed script on Frame 1 on the root timeline and I am getting a few erroe messages and I am posting them below. I am also attaching a jpeg of my layer structure to give you a visual which may be better. I know that some of these errors may be because I am testing this locally on my HD but not entirely sure. Really appreciate your help and quick response on this issue.


    These errors are from the output report:

    **Error** Scene=Scene 1, layer=Actions, frame=1, Line 1: Syntax error.
    onLoad () {

    **Error** Scene=Scene 1, layer=Actions, frame=1, Line 2: The identifier 'date' will not resolve to built-in object 'Date' at runtime.
    mydate = new date();

    **Error** Scene=Scene 1, layer=Actions, frame=1, Line 6: Syntax error.
    onFrame (1) {

    Total ActionScript Errors: 3, Reported Errors: 3
    Attached Images Attached Images

  8. #8
    Senior Member
    Join Date
    Oct 2004
    Posts
    2,049
    Here is a sample for you. saved as Flash 8 AS 2
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center