A Flash Developer Resource Site

Page 1 of 4 1234 LastLast
Results 1 to 20 of 61

Thread: ADVENT CALENDAR - Doors not to be opened before date...

  1. #1
    Senior Member
    Join Date
    Oct 2006
    Posts
    114

    ADVENT CALENDAR - Doors not to be opened before date...

    Hi,
    I'm making an advent calander for work and need to figure out how to make the doors not open unless it is the correct date.

    Pleeeeeeeeeeeeeeeeease help someone or I'll get the sack!!... well maybe not but I won't be in anyones good books!!
    Thanks loads in advance.
    Stefan
    Last edited by stefancostain; 11-29-2007 at 07:05 AM.

  2. #2
    Senior Member
    Join Date
    Oct 2002
    Location
    Copenhagen
    Posts
    228
    I suppose your doors has some kind of numeric order. Just activate the door that corresponds with todays date. A simple way to retrieve this day would be

    Code:
    var todaysDate:Date = new Date();
    var active_date = (Number(todaysDate.getDate()));
    trace(active_date)

  3. #3
    Senior Member
    Join Date
    Oct 2006
    Posts
    114
    Thanks a lot for that. I'm a bit unsure how to use this code though? Do I put it on the timeline or instance? What parts of the code if any do I change?

  4. #4
    Senior Member
    Join Date
    Oct 2002
    Location
    Copenhagen
    Posts
    228
    don't change anything. I would the function, that opens the doors with the active_date as a parameter:

    Code:
    function open_door_function(active_date){
       //this function opens door where door_number equals active_date
    }
    
    var todaysDate:Date = new Date();
    var active_date = (Number(todaysDate.getDate()));
    trace(active_date)
    
    open_door_function(active_date);

  5. #5
    Senior Member
    Join Date
    Oct 2002
    Location
    Copenhagen
    Posts
    228
    Don't know how your movie is structured, but normally this code would be placed on the time line.

  6. #6
    Senior Member
    Join Date
    Oct 2006
    Posts
    114
    Hmmm,
    thanks again but I'm still a bit confused. I just put it on the timeline. I have a door which is an instance and named door1. It opens when I click on it.

  7. #7
    Senior Member
    Join Date
    Oct 2002
    Location
    Copenhagen
    Posts
    228
    well .. if you have 24 movieclips named door0, door1, door2, door3 etc, each with and opendoor-animation you would have to deactivate all doors except the door that corresponds with todays date. Perhaps something like this would do the trick for you:

    Code:
    var todaysDate:Date = new Date();
    var active_date = (Number(todaysDate.getDate()));
    
    // DISABLE ALL DOORS AND ENABLE ONLY THE DOOR
    // THAT CORRESPONDS WITH TODAYS DATE
    function disable_doors(){
    	
    	// loop through all door-movieclips
    	for (var i:Number = 0; i < 24; i++){
    		_root["door" + i].enabled = false;
    	}
    	
    	// reactivate todays-date-door
    	_root["door" + active_date].enabled = true;
    	
    }
    Place this code in the timeline in the same frame as your door-movieclips. Does this give you an idea of where to go?

  8. #8
    Senior Member
    Join Date
    Oct 2006
    Posts
    114
    Hi hope I'm not annoying u with this but I just tried the code. I even tried to change it to door29 as I thought it might be referring to the number written in the instance name.
    Just so u understand a bit more how its structured I have a movie named door and a stop action at the beginning and end of that. Its made into an instance named door with a btn over the top that says when clicked play movie. I only have one door so far but I'm looking to make more and name them like you said door1, door2 ect.
    Thanks!!
    Stefan

  9. #9
    Senior Member
    Join Date
    Oct 2002
    Location
    Copenhagen
    Posts
    228
    Attach your .fla and I'll take a look at it. Might be a lot easier .. :-)

  10. #10
    Senior Member
    Join Date
    Oct 2006
    Posts
    114
    k. having probs uploading. Going to luch now but will try again when I get back. Thanks for you help so far!!

  11. #11
    Senior Member
    Join Date
    Oct 2006
    Posts
    114

    hi...

    Sorry don't know what was wrong with it before. Here it is. I've taken away everything that doesn't apply to this e.g. background.

  12. #12
    Senior Member
    Join Date
    Oct 2006
    Posts
    114

    ...

    sorry here's the file.
    Attached Files Attached Files

  13. #13
    Senior Member
    Join Date
    Oct 2002
    Location
    Copenhagen
    Posts
    228
    Seems like a version cs3? Anyway I can't open the attached file. Could you save it as a version 8. I presume you are using Actionscript 2.0?

  14. #14
    Senior Member
    Join Date
    Oct 2006
    Posts
    114

    sorry...

    sorry here u go.

  15. #15
    Senior Member
    Join Date
    Oct 2006
    Posts
    114

    ...

    ... sorry uploads were full
    Attached Files Attached Files

  16. #16
    Senior Member
    Join Date
    Oct 2006
    Posts
    114
    My boss just came over stressing at me. He's gonna make me stay if I don't get this done and I have no clue what to do to get it working!! Pllllllllllleeeeeease!!! Someone help!!!! Thanks!!!!!!!!!!!!!!!!!!

  17. #17
    Senior Member
    Join Date
    Oct 2002
    Location
    Copenhagen
    Posts
    228
    take a look at the attached file. This should do the trick.

    Perhaps you should have started the project a little earlier :-)
    Last edited by lash; 03-11-2008 at 05:10 AM.

  18. #18
    Senior Member
    Join Date
    Oct 2006
    Posts
    114

    Thanks!!!!!!!!!!...

    Thanks so much. I know I should have started earlier but I've had loads of work this week and haven't had the chance. So with this code I notice if you change the number at the top - var active_date:Number = 21; it opens that day. So do I have to change the code daily as this wont be ok with mr boss-man.
    Thanks sooooooo much tho.
    Last edited by stefancostain; 11-29-2007 at 11:29 AM.

  19. #19
    Senior Member
    Join Date
    Oct 2002
    Location
    Copenhagen
    Posts
    228
    just delete:
    Code:
    var active_date:Number = 5;
    and insert:
    Code:
    var active_date = (Number(todaysDate.getDate()));
    -instead. This code automatically retrieves todays date from the clients computer

  20. #20
    Senior Member
    Join Date
    Oct 2002
    Location
    Copenhagen
    Posts
    228
    Since todays date is the 29th, this date woul'nt works, since there is only 24 doors. Therefore I inserted a fake date. The final code should then look like this :


    Code:
    var todaysDate:Date = new Date();
    var active_date = (Number(todaysDate.getDate()));
    
    function init(){
    	date_door_mc._visible = false;
    	
    	for (var i:Number = 0; i < 24; i++){
    		date_door_mc.duplicateMovieClip("door_" + i, _root.getNextHighestDepth());
    		
    		if (i < 5){
    			_root["door_" + i]._x = (_root.date_door_mc._width + 5) * i + 10;
    			_root["door_" + i]._y = 10
    		}else if (i < 10){
    			_root["door_" + i]._x = (_root.date_door_mc._width + 5) * (i-5) + 10;
    			_root["door_" + i]._y = 100
    		}else if (i < 15){
    			_root["door_" + i]._x = (_root.date_door_mc._width + 5) * (i-10) + 10;
    			_root["door_" + i]._y = 200
    		}else if (i < 20){
    			_root["door_" + i]._x = (_root.date_door_mc._width + 5) * (i-15) + 10;
    			_root["door_" + i]._y = 300
    		}else if (i < 25){
    			_root["door_" + i]._x = (_root.date_door_mc._width + 5) * (i-20) + 10;
    			_root["door_" + i]._y = 400
    		}
    		_root["door_" + i].date_txt.text = i+1;
    		
    		_root["door_" + i].onRelease = function(){
    			_root["door_" + (this._name.substr(5,2))].door_mc._visible = false;
    			this.enabled = false;
    			
    		}
    		
    		_root["door_" + i].enabled = false;
    		
    	}
    	
    	_root["door_" + (active_date-1)].enabled = true;
    	
    }
    
    
    init();

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