Actionscripts 3 功能不起作用
Actionscripts 3 Function doesn't work
我写了一些代码来获取当前日期并将其与将来的日期进行比较以限制应用程序。不知道为什么这个功能不起作用
getYYMMDD();
function getYYMMDD(): String {
var dateObj: Date = new Date();
var year: String = String(dateObj.getFullYear());
var month: String = String(dateObj.getMonth() + 1);
if (month.length == 1) {
month = "0" + month;
}
var date: String = String(dateObj.getDate());
if (date.length == 1) {
date = "0" + date;
}
return year.substring(0, 4) + month + date;
trace(year + ":" + month + ":" + date);
if (int(year) > 2017 && int(month) > 5 && int(date) > 31) {
trace("SYSTEM TIME IS OFF.");
} else {
trace("SYSTEM TIME IS ON.");
}
}
(1) 因为你的函数 returns String
类型的数据...
function getYYMMDD(): String
确保返回的数据也被字符串接收... ie: someString = getYYMMDD();
表示someString
现在已经从函数返回值。
(2) 你return
(退出函数)太早了...
将 return
作为最后一个命令,以允许函数内的所有其他代码到 运行。
(3) 你应该考虑返回一个 Boolean
类型 (true/false)...
var can_Start : Boolean = false; //# assume false before checking
can_Start = getYYMMDD(); //# use function to update status to true/false
if (can_Start == true) { run_Program(); }
else { trace("Sorry time has expired"); }
function getYYMMDD(): Boolean
{
var dateObj: Date = new Date();
var year: String = String(dateObj.getFullYear());
var month: String = String(dateObj.getMonth() + 1);
if (month.length == 1) { month = "0" + month; }
var date: String = String(dateObj.getDate());
if (date.length == 1) { date = "0" + date; }
trace(year + ":" + month + ":" + date);
if(int(year) == 2017)
{
if(int(month) >= 05 && int(date) > 31)
{ trace("SYSTEM TIME IS OFF."); can_Start = false; } //# can_Start == false;
else { trace("SYSTEM TIME IS ON."); can_Start = true; } //# can_Start == true;
}
return can_Start;
}
我写了一些代码来获取当前日期并将其与将来的日期进行比较以限制应用程序。不知道为什么这个功能不起作用
getYYMMDD();
function getYYMMDD(): String {
var dateObj: Date = new Date();
var year: String = String(dateObj.getFullYear());
var month: String = String(dateObj.getMonth() + 1);
if (month.length == 1) {
month = "0" + month;
}
var date: String = String(dateObj.getDate());
if (date.length == 1) {
date = "0" + date;
}
return year.substring(0, 4) + month + date;
trace(year + ":" + month + ":" + date);
if (int(year) > 2017 && int(month) > 5 && int(date) > 31) {
trace("SYSTEM TIME IS OFF.");
} else {
trace("SYSTEM TIME IS ON.");
}
}
(1) 因为你的函数 returns String
类型的数据...
function getYYMMDD(): String
确保返回的数据也被字符串接收... ie: someString = getYYMMDD();
表示someString
现在已经从函数返回值。
(2) 你return
(退出函数)太早了...
将 return
作为最后一个命令,以允许函数内的所有其他代码到 运行。
(3) 你应该考虑返回一个 Boolean
类型 (true/false)...
var can_Start : Boolean = false; //# assume false before checking
can_Start = getYYMMDD(); //# use function to update status to true/false
if (can_Start == true) { run_Program(); }
else { trace("Sorry time has expired"); }
function getYYMMDD(): Boolean
{
var dateObj: Date = new Date();
var year: String = String(dateObj.getFullYear());
var month: String = String(dateObj.getMonth() + 1);
if (month.length == 1) { month = "0" + month; }
var date: String = String(dateObj.getDate());
if (date.length == 1) { date = "0" + date; }
trace(year + ":" + month + ":" + date);
if(int(year) == 2017)
{
if(int(month) >= 05 && int(date) > 31)
{ trace("SYSTEM TIME IS OFF."); can_Start = false; } //# can_Start == false;
else { trace("SYSTEM TIME IS ON."); can_Start = true; } //# can_Start == true;
}
return can_Start;
}