根据时间和星期几返回不同的文本

时间:2015-09-18 06:56:39

标签: actionscript-3 flash actionscript dynamic-text

我正在寻找一种方法,基本上是为我的电脑编写闹钟。我希望它显示时间,星期几,月和日,然后根据它,我希望它显示一条消息并播放一次声音。我在舞台上有四个动态文本框:时间,显示,日期,日期。

import flash.net.URLRequest;
import flash.media.Sound;

time.text = getTime();
function getTime(){
    var time = new Date();
    var hour = time.getHours();
    var minute = time.getMinutes();
    var temp = "" + ((hour > 12) ? hour - 12 : hour);
    temp += ((minute < 10) ? ":0" : ":") + minute;
    temp += (hour >= 12) ? " PM" : " AM";
    return temp;
}

day.text = getToday();
function getToday(){
    var weekday_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
    var today = new Date();
        var weekday:String = weekday_array[today.getDay()];
        var temp = weekday + ","; 
    return temp;
}

date.text = getDayz();
function getDayz() {
    var month_array:Array = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    var calendar = new Date();
        var number = calendar.getDate();
        var month:String = month_array[calendar.getMonth()];
        var temp = month + " ";
        temp += number;  
   return temp;
}

    display.text = getDisplay();
    function getDisplay(){
        time.text = getTime();
        day.text = getToday();
        date.text = getDayz();

}

没有display.text块,一切都很完美。当我尝试通过执行for或if函数来调整最后一点时,它会抛弃整个事物。

如何让显示文本框读取其他框中的内容,然后根据这些值返回一个短语?四年前我参加了一个基本课程,所以外行人的学期将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

首先,关于您的DB::table('transaction_details') ->join('ledger','transaction_details.ledger','=','ledger.Name') ->groupBy('ledger.Name') ->select( 'ledger.CrDr as CrDr', 'transaction_details.ledger as Name', 'transaction_details.amount as Debit', DB::raw('ABS(ledger.OpeningBalance) as openingBalance') )->get(); 函数,您应该知道如果您希望文本字段的文本获得返回值 一个函数你必须在该函数中使用“return”来返回一个String对象(正如你对其他3个函数所做的那样)。

此外,在将其设置为最终文本字段之前,您不必使用文本字段来放置信息。

因此,在您的情况下,如果您不需要使用getDisplay()timeday文本字段,则可以像这样设置date

display.text

但是你可以使用一个display.text = getTime() + getToday() + getDayz(); 对象来更简化一些事情,它会为你完成工作,你只需在文本字段中显示你需要的内容,如下所示:

flash.globalization.DateTimeFormatter

当然,您可以将这些值放入变量中,然后将它们与文本字段一起使用。

有关// I'm not in USA, that's why I used "en-US" to get the english format (for the example) // for you, you can simply use LocaleID.DEFAULT, you will get your local format var df:DateTimeFormatter = new DateTimeFormatter('en-US'); // get the time // hh : hour of the day in a 12-hour format in two digits [01 - 12] // mm : minute of the hour in two digits [00 - 59] // a : AM/PM indicator df.setDateTimePattern('hh:mm a'); trace(df.format(new Date())); // gives : 11:02 AM // get the day // EEEE : full name of the day in week df.setDateTimePattern('EEEE'); trace(df.format(new Date())); // gives : Friday // get the day and month // MMMM : full name of the month // dd : day of the month in two digits [01 - 31] df.setDateTimePattern('MMMM dd'); trace(df.format(new Date())); // gives : September 18 对象用于设置日期和时间格式的模式字符串的更多详细信息,请查看setDateTimePattern() function

希望可以提供帮助。

相关问题