# AS3 Day night simulator

**URL:** https://forum.kirupa.com/t/as3-day-night-simulator/330060
**Category:** flash
**Created:** [November 24, 2012, 4:02pm UTC](https://forum.kirupa.com/t/as3-day-night-simulator/330060 "2012-11-24T16:02:14Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Hvdstaal](https://avatars.discourse-cdn.com/v4/letter/h/7cd45c/32.png) [@Hvdstaal](https://forum.kirupa.com/u/Hvdstaal)
#### Post date: [November 24, 2012, 4:02pm UTC](https://forum.kirupa.com/t/as3-day-night-simulator/330060/1 "2012-11-24T16:02:14Z")

</div>

Hello all!  
So what i’m trying to create is a landscape with an actual time-based day and night background(sun, moon).  
This is what i have:  
night\_mc is a layer for the darkness of the night, set on multiply and the code controls the alpha-channel.

```auto
stage.root.addEventListener(Event.ENTER_FRAME, renew); 

function renew(e:Event):void{
        getTime();
}

function getTime():void{
var now:Date = new Date();
var sec:Number = now.getSeconds();

if (sec > 14 && sec < 44){
    night_mc.gotoAndPlay("nightoff");

}else if(sec < 45 || sec > 15){
    night_mc.gotoAndPlay("night_on");

}
}

```

I’m doing it with seconds so i wont have to wait 6 hours.  
But the problem is that i want to have 4 stages of darkness.

- sunset (little bit dark)
- day (normal)
- dawn (little bit dark)
- night (dark)

But somehow that wont work.  
Can somebody help me?
