Flash coders help
- Started
- Last post
- 10 Responses
- Elfangio
Hello,
I dunno so much about OOP, or programming. I do know some action script but I take a lot of time to develop anything. I need some help to build a simple function ( for me is not that simple thought). I need to have a function that depending on the week day and time will display a "close" or "opened" or "lunch time" mc. If there is out there a programmer soul that have time to help me, I promise his/her name will be in the credits of the site.
I already googled but didn't find nothing similar...
cheers
- fyoucher10
just lookup Date methods- getYear getMonth getDate etc...then just simple if/else statements..i.e. if the date is between here and there and time is between here and there, do this...
- yes I am doing it right now, taking my time thought :D anyway thatnks ;) - no your name is not going to the credits hahahahaElfangio
- skelly_b0
it should be pretty simple...
var currentTime:Date = new Date();
var hour:uint = currentTime.getHours();Then just add the logic, if hour is less than this display "closed" sign. If greater than that display "open" and so on...
- Elfangio0
Yes, thats the right path I guess, BUT what happens when is Sunday?? I am trying stuff like this...
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var today_date:Date = new Date();
var day_str:String = dayOfWeek_array[today_date.getDa...
trace("Today is "+day_str);var my_date:Date = new Date();
var hourObj:Object = getHoursAmPm(my_date.getHours...if (!day_str[0] && hourObj >= 12) {
trace("YES");
} else {
trace("NO")
}I am close I know, but still very far thought i am kind of feelling a little lost here...
- maximillion_0
which version as2 or as3?
- Elfangio0
this code is almost working, but I can make the hours working. Any help?
fechado_mc._visible = false;
aberto_mc._visible = false;var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var today_date:Date = new Date();
var day_str:String = dayOfWeek_array[today_date.getDa...var currentTime:Date = new Date();
var hourObj:Object = currentTime.getHours();
var currentTime:String = hourObj.toString();if (day_str == "Monday" || day_str == "Tuesday" || day_str == "Wednesday" || day_str == "Thursday" || day_str == "Friday" || day_str == "Saturday") {
trace("Hoje estamos abertos");
aberto_mc._visible = true;
} else {
fechado_mc._visible = true;
trace("Aos domingos não estamos abertos")}
trace("Today is "+day_str);
trace(currentTime);
- maximillion_0
yr if statement would be better as
if(day_str != "Sunday"){// not equal to sunday
aberto_mc._visible = true;
fechado_mc._visible = false;
}else{
aberto_mc._visible = false;
fechado_mc._visible = true;
}you need to say what you want to with the hours for ppl to help
- maximillion_0
getHours() returns a number but you have it defied as an object
var currentTime:Date = new Date();
var hourObj:Object = currentTime.getHours();
var currentTime:String = hourObj.toString();should be
var currentTime:Date = new Date();
var hours:Number= currentTime.getHours();
//var currentTime:String = hourObj.toString(); // you dont need this line
- Elfangio0
Thanks I already got it :), i did that last line in the currentTime because i was getting a weird number :D this is my last code, working:
fechado_mc._visible = false;
aberto_mc._visible = false;var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var today_date:Date = new Date();
var day_str:String = dayOfWeek_array[today_date.getDa...var currentTime:Date = new Date();
var hourObj:Object = currentTime.getHours();
var currentTime:String = hourObj.toString();if ( (day_str == "Monday" || day_str == "Tuesday" || day_str == "Wednesday" || day_str == "Thursday" || day_str == "Friday" || day_str == "Saturday") && (currentTime >= 10 && currentTime <= 20)) {
trace("Hoje estamos abertos");
aberto_mc._visible = true;
} else {
fechado_mc._visible = true;
trace("Aos domingos não estamos abertos")}
- Elfangio0
I still have to work a little more in a way to make the lunch time, and perfect perfect would be to get the hours from the server, not from the client...but this will do at least in the local visitors.
cheers
- maximillion_0
did you actually read my post?
this line is wrong
var hourObj:Object = currentTime.getHours();
- hour:int would be best.. me thinks.skelly_b
- as2 dudemaximillion_