A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Day/Night Cycle Issues

  1. #1

    Question Day/Night Cycle Issues

    Okay, so I'm making a flash site that's supposed to have a day/night cycle that works in real time

    Right now, the plan is to have a ten frame animation play once and stop after it reached the end of the movieclip timeline when the clock hits a certain time and a movie is loaded


    The problem is that whenever try testing the animation, it loops. I believe the problem is that a duplicate of the movieclip keeps attaching itself in the original's place

    PHP Code:
    stop();

    var 
    updateTime setInterval(currenttime1000);
    function 
    currenttime() {
        var 
    today = new Date();
        var 
    minutes today.getMinutes();
        var 
    hours today.getHours();
        
    trace(today);
        
    trace(minutes);
        
    trace(hours);
        var 
    DAWN hours == && minutes == 00;
        var 
    DAY hours == 20 && minutes == 15;
        if (
    DAWN<today) {
            
    attachMovie("TownEarly""TownEarly"10);
            
    unloadMovie(TownDay);
            
    trace("It is dawn");
        }
        if (
    DAWN<DAY) {
            
    attachMovie("TownDay""TownDay"10);
            
    unloadMovie(TownEarly);
            
    trace("It is day");
        }

    Is there a way to check if a movieclip is already attached and then prevent a duplicate from taking it's place

  2. #2
    Senior Member
    Join Date
    May 2016
    Posts
    451
    try this

    PHP Code:
    this.removeMovieClip('TownEarly'); 
    or try

    PHP Code:
    TownEarly.removeMovieClip(); 
    Last edited by kofa; 05-09-2022 at 02:02 PM.

  3. #3
    Doesn't seem to be working
    Last edited by ponponz; 05-09-2022 at 06:23 PM.

  4. #4
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,834
    I'd suggest instead of add/removing the movieclips, you just switch which one is visible. Maybe something like: TownEarly._visible = false;
    .

  5. #5
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Maybe use booleans to remember if dawn or day has been used before.

    PHP Code:
    //v1
    stop();

    var 
    updateTime setInterval(currenttime1000);
    var 
    attached_dawn=false
    var attached_day=false
    function currenttime() {
        var 
    today = new Date();
        var 
    minutes today.getMinutes();
        var 
    hours today.getHours();
        
    trace(today);
        
    trace(minutes);
        
    trace(hours);
        var 
    DAWN hours == && minutes == 00;
        var 
    DAY hours == 20 && minutes == 15;
        if (
    DAWN<today) {
            if(
    attached_dawn==false){
            
    attachMovie("TownEarly""TownEarly"10);
           
    attached_dawn=true;
            }
            
    unloadMovie(TownDay);
            
    trace("It is dawn");
        }
        if (
    DAWN<DAY) {
            if(
    attached_day==false){
            
    attachMovie("TownDay""TownDay"10);
           
    attached_day=true;
            }
            
    unloadMovie(TownEarly);
            
    trace("It is day");
        }


    Here is an extra program just incase.

    attach TownEarly, wait for it to reach its max frames, unload it, now attach TownDay, wait for it to reach its max frames, unload it, now start over? or attach a new thing.

    TownEarly I put 10 frames with stop(); at last frame, TownDay I put 10 frames with stop(); at the last frame

    PHP Code:
    //v2
    stop();

    var 
    updateTime setInterval(currenttime1000);
    var 
    attached_dawn=false
    function currenttime() {
     var 
    today = new Date();
     var 
    minutes today.getMinutes();
     var 
    hours today.getHours();
     
    trace(today);
     
    trace(minutes);
     
    trace(hours);
     var 
    DAWN hours == && minutes == 00;
     var 
    DAY hours == 20 && minutes == 15;
      

    if(
    attached_dawn==false){//start attach TownEarly
    attachMovie("TownEarly""TownEarly"10);
    attached_dawn=true;
    }

    if(
    TownEarly._currentframe==TownEarly._totalframes&&TownEarly!=undefined){//TownEarly reached max frames, attach townDay
    unloadMovie(TownEarly);
    attachMovie("TownDay""TownDay"10);
    }

    if(
    TownDay._currentframe==TownDay._totalframes&&TownDay!=undefined){//TownDay reached max frames, attach TownEarly
    unloadMovie(TownDay);
    attachMovie("TownEarly""TownEarly"10);
    }
        


    This one is like the second version but with depth management if you have problems attaching multiple things.

    PHP Code:
    //v3
    stop();

    var 
    updateTime setInterval(currenttime1000);
    var 
    attached_dawn=false
    var depth=10;
    var 
    last_obj=null
    function currenttime() {
     var 
    today = new Date();
     var 
    minutes today.getMinutes();
     var 
    hours today.getHours();
     
    trace(today);
     
    trace(minutes);
     
    trace(hours);
     var 
    DAWN hours == && minutes == 00;
     var 
    DAY hours == 20 && minutes == 15;
      

    if(
    attached_dawn==false){//start attach TownEarly
    attachMovie("TownEarly""TownEarly"+depthdepth);
    last_obj=_root["TownEarly"+depth]
    _root["TownEarly"+depth].name="TownEarly"
    attached_dawn=true;
    depth++
    }

    if(
    last_obj._currentframe==last_obj._totalframes&&last_obj!=undefined&&last_obj.name=="TownEarly"){//TownEarly reached max frames, attach townDay
    unloadMovie(last_obj);
    attachMovie("TownDay""TownDay"+depthdepth);
    last_obj=_root["TownDay"+depth]
    _root["TownDay"+depth].name="TownDay"
    depth++
    }

    if(
    last_obj._currentframe==last_obj._totalframes&&last_obj!=undefined&&last_obj.name=="TownDay"){//TownDay reached max frames, attach TownEarly
    unloadMovie(last_obj);
    attachMovie("TownEarly""TownEarly"+depthdepth);
    last_obj=_root["TownEarly"+depth]
    _root["TownEarly"+depth].name="TownEarly"
    depth++
    }
        

    Last edited by AS3.0; 05-10-2022 at 01:31 PM.

Tags for this Thread

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