主屏幕按钮

时间:2011-05-16 14:46:56

标签: actionscript-3

我找出了公交时刻表的代码,但我需要帮助在链接到所有这些代码的实际时间表之前创建一个主屏幕。

感谢所有在之前发布答案的人帮帮我了!

var myDate:Date = new Date();
var countdown:Number

//Shuttle bus to CSI
var busHours:Array = new Array(); 
busHours[0] = ["2CSI", 7, 05]; 
busHours[1] = ["2CSI", 7, 35]; 
busHours[2] = ["2CSI", 8, 05]; 
busHours[3] = ["2CSI", 8, 35]; 
busHours[4] = ["2CSI", 9, 05]; 
busHours[5] = ["2CSI", 9, 35]; 
busHours[6] = ["2CSI", 10, 05]; 
busHours[7] = ["2CSI", 10, 35];
busHours[8] = ["2CSI", 11, 05];
busHours[9] = ["2CSI", 11, 35];
busHours[10] = ["2CSI", 12, 05];
busHours[11] = ["2CSI", 12, 35];
busHours[12] = ["2CSI", 13, 05];
busHours[13] = ["2CSI", 13, 35];
busHours[14] = ["2CSI", 14, 05];
busHours[15] = ["2CSI", 14, 35];
busHours[16] = ["2CSI", 15, 05];
busHours[17] = ["2CSI", 15, 35];
busHours[18] = ["2CSI", 16, 05];
busHours[19] = ["2CSI", 16, 35];
busHours[20] = ["2CSI", 17, 05];
busHours[21] = ["2CSI", 17, 35];
busHours[22] = ["2CSI", 18, 05];
busHours[23] = ["2CSI", 18, 35];
busHours[24] = ["2CSI", 19, 05];
busHours[25] = ["2CSI", 19, 35];
busHours[26] = ["2CSI", 20, 05];
busHours[26] = ["2CSI", 20, 35];
busHours[26] = ["2CSI", 21, 05];
busHours[26] = ["2CSI", 21, 35];
busHours[26] = ["2CSI", 22, 05];
busHours[26] = ["2CSI", 22, 35];

for (var i:Number = 0; i < busHours.length; i++) { 

if(myDate.hours < busHours[i][1] || myDate.hours == busHours[i][1] && myDate.minutes <= busHours[i][2]){
    trace(busHours[i][1]);
    if(busHours[i][1] == myDate.hours){
        countdown = busHours[i][2] - myDate.minutes;
    } else {
        countdown = 60 - myDate.minutes + busHours[i][2];

    }

    csi.text = "The next Shuttle bus to CSI arrives at " + busHours[i][1] + ":" + busHours[i][2] + " in " + countdown + " minute(s)";
    i += busHours.length;
} else {

    csi.text = "There are no more Shuttle buses arriving at The College of Staten Island at this time.";

}

}

//Shuttle Bus to ferry
var FerrybusHours:Array = new Array(); 
FerrybusHours[0] = ["2Ferry", 7, 35]; 
FerrybusHours[1] = ["2Ferry", 8, 05]; 
FerrybusHours[2] = ["2Ferry", 8, 35]; 
FerrybusHours[3] = ["2Ferry", 9, 05]; 
FerrybusHours[4] = ["2Ferry", 9, 35]; 
FerrybusHours[5] = ["2Ferry", 10, 05]; 
FerrybusHours[6] = ["2Ferry", 10, 35]; 
FerrybusHours[7] = ["2Ferry", 11, 05];
FerrybusHours[8] = ["2Ferry", 11, 35];
FerrybusHours[9] = ["2Ferry", 12, 05];
FerrybusHours[10] = ["2Ferry", 12, 35];
FerrybusHours[11] = ["2Ferry", 13, 05];
FerrybusHours[12] = ["2Ferry", 13, 35];
FerrybusHours[13] = ["2Ferry", 14, 05];
FerrybusHours[14] = ["2Ferry", 14, 35];
FerrybusHours[15] = ["2Ferry", 15, 05];
FerrybusHours[16] = ["2Ferry", 15, 35];
FerrybusHours[17] = ["2Ferry", 16, 05];
FerrybusHours[18] = ["2Ferry", 16, 35];
FerrybusHours[19] = ["2Ferry", 17, 05];
FerrybusHours[20] = ["2Ferry", 17, 35];
FerrybusHours[21] = ["2Ferry", 18, 05];
FerrybusHours[22] = ["2Ferry", 18, 35];
FerrybusHours[23] = ["2Ferry", 19, 05];
FerrybusHours[24] = ["2Ferry", 19, 35];
FerrybusHours[25] = ["2Ferry", 20, 05];
FerrybusHours[26] = ["2Ferry", 20, 35];
FerrybusHours[27] = ["2Ferry", 21, 05];
FerrybusHours[28] = ["2Ferry", 21, 35];
FerrybusHours[29] = ["2Ferry", 22, 05];
FerrybusHours[30] = ["2Ferry", 22, 35];
FerrybusHours[31] = ["2Ferry", 23, 05];

for (var f:Number = 0; f < FerrybusHours.length; f++) { 

if(myDate.hours < FerrybusHours[f][1] || myDate.hours == FerrybusHours[f][1] && myDate.minutes <= FerrybusHours[f][2]){
    trace(FerrybusHours[f][1]);
    if(FerrybusHours[f][1] == myDate.hours){
        countdown = FerrybusHours[f][2] - myDate.minutes;
    } else {
        countdown = 60 - myDate.minutes + FerrybusHours[f][2];

    }

    ferry.text = "The next Shuttle bus to the Ferry Terminal arrives at " + FerrybusHours[f][1] + ":" + FerrybusHours[f][2] + " in " + countdown + " minute(s)";
    f += FerrybusHours.length;
} else {

    ferry.text = "There are no more Shuttle buses arriving at the ferry terminal at this time.";

}


}

1 个答案:

答案 0 :(得分:1)

从您的帖子中可以看出,您正在使用Flash IDE并在时间轴中进行编码。如果不是这种情况,那么你可能想忽略这一点。

您可以添加一个事件侦听器来检查单击按钮/动画片段的时间,并将总线代码和资源放在第二帧上。在第一帧框架上放置代码:

button.addEventListener(MouseEvent.CLICK,clickButton);
function clickButton(e:MouseEvent){
   gotoAndStop(2);
}

现在,当您单击按钮时,它应移至第2帧并运行您的总线代码。