无法在 AS3 中更改动态文本



这是整个项目的链接,如果需要,包括所有依赖项。 https://www.dropbox.com/sh/3d3towtkhb4c38r/AADdxDJq9ix7bK9hTkt_VTSAa?dl=0

基本上试图清理一些我留下来处理的脚本,并且一直在用头撞墙,为什么这不起作用。我没有收到任何调试错误,所有内容似乎都链接到需要链接的地方。我的字体似乎被嵌入了,我所有的实例名称似乎都是正确的......我唯一能想到的是我在代码中缺少一些愚蠢的东西。任何帮助将不胜感激!没有什么比被留下一团糟并不得不修复它了。

基本上,文本框应该有一个基于比赛接近的倒数计时器(例如,比赛 X 以 xxx 分钟为单位),如果没有比赛接近,它应该显示一些默认文本。目前,它似乎根本不想更改动态文本!

编辑:我还将提到包含文本的RaceRibbon Movieclip也导出为as3到com。比赛丝带类。

package  {
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.ui.Mouse;
import flash.utils.Timer;
import com.boo.CustomDate;
import com.boo.ScreensaverSimple;
import com.RaceRibbon;
// This sections is for the image slides and Hour Of Power setting.
public class Generic extends MovieClip {
// This is where you can set the Hour of Power time start and end time (in 24 hour format e.g. 1330 for 1:30pm)
// If there is no hour of power, simply set both numbers to 0
private var HourOfPowerStartTime:Number = 0;
private var HourOfPowerEndTime:Number = 0;
private var HourOfPower1StartTime:Number = 0;
private var HourOfPower1EndTime:Number = 0;

public var race_ribbon:RaceRibbon;      
private var ss:ScreensaverSimple;
public var time_check_timer:Timer;
public var is_race_time:Boolean;
public var current_state:String;
public var next_race:Date;
public var race_time_arr:Array;
public var race_num:int;
private var ss_time_arr:Array;      
private var delay_add_timer:Timer;
//Set default text
private var default_ribbon_text:String = "THERACES.COM.AU";
// Set Race Times
private var r1:Date = new Date(2017,5,5,12,15);
private var r2:Date = new Date(2017,5,5,12,50);
private var r3:Date = new Date(2017,5,5,13,25);
private var r4:Date = new Date(2017,5,5,14,00);
private var r5:Date = new Date(2017,5,5,14,35);
private var r6:Date = new Date(2017,5,5,15,15);
private var r7:Date = new Date(2017,5,5,15,55);
private var r8:Date = new Date(2017,5,5,16,35);
private var r9:Date = new Date(2017,5,5,17,15);

// Hide the mouse
public function Generic() {
Mouse.hide();
// Set Race Ribbon
race_ribbon = new RaceRibbon;
race_ribbon.x = 1109;
race_ribbon.y = 983;
race_time_arr = [r1,r2,r3,r4,r5,r6,r7,r8,r9];
// Display Slideshow
ss = new ScreensaverSimple;
ss.setScreensaver(screens);
// Make sure Hour of Power is not visible
HOP1.visible = false;
HOP2.visible = false;

time_check_timer = new Timer(1000);
time_check_timer.addEventListener(TimerEvent.TIMER, checkTime);
delay_add_timer = new Timer(1,1);
delay_add_timer.addEventListener(TimerEvent.TIMER, addAllChildren);
delay_add_timer.start();    
}

public function addAllChildren(evt:TimerEvent=null):void {
delay_add_timer.removeEventListener(TimerEvent.TIMER, addAllChildren);
delay_add_timer.stop();
delay_add_timer = null;
addChild(race_ribbon);
time_check_timer.start();
checkTime();
}

public function checkTime(evt:TimerEvent=null):void {
setDatesToCurrent(race_time_arr);// This makes every day race day
setDatesToCurrent(ss_time_arr);// This makes all screensaver dates current
checkNextRace();
if(next_race  != null && is_race_time == false)// If it isn't race time
{
setCountdown();
}
if(next_race  == null && is_race_time == true)// If it's race time
{
setDefaultText();
}
checkHOP1();
checkHOP2();
}
//Call to make Hour Of Power 1 visible/invisible based on set times
private function checkHOP1():void {
HOP1.visible = (HourOfPowerStartTime || HourOfPowerEndTime);
if (!HOP1.visible) return;
var CurrentTime:Number = CustomDate.return24HourNumber();
HOP1.visible = (CurrentTime >= HourOfPowerStartTime && CurrentTime <= HourOfPowerEndTime);
}
//Call to make Hour Of Power 2 visible/invisible based on set times
private function checkHOP2():void {
HOP2.visible = (HourOfPower1StartTime || HourOfPower1EndTime);
if (!HOP2.visible) return;
var CurrentTime:Number = CustomDate.return24HourNumber();
HOP2.visible = (CurrentTime >= HourOfPower1StartTime && CurrentTime <= HourOfPower1EndTime);
}
public function setDatesToCurrent(arr:Array):void {// This makes every day race day
var cd:Date = new Date();// Current Date
for(var i:int=0;i<arr.length;i++){
arr[i].fullYear = cd.fullYear;
arr[i].month = cd.month;
arr[i].date = cd.date;
}
}       
public function checkNextRace():void {
var ct:Date = new Date();// Current Time as a Date
next_race = null;
is_race_time = false;
// FOR LOOP THIS... one day
if(ct < r1) {
next_race = r1;
} else if(raceTimeSpan(r1) == true) {
is_race_time = true;
race_num = 1;
} else if(ct > raceTimeSpan(r1) && ct < r2) {
next_race = r2;
} else if(raceTimeSpan(r2) == true) {
is_race_time = true;
race_num = 2;
} else if(ct > raceTimeSpan(r2) && ct < r3) {
next_race = r3;
} else if(raceTimeSpan(r3) == true) {
is_race_time = true;
race_num = 3;
} else if(ct > raceTimeSpan(r3) && ct < r4) {
next_race = r4;
} else if(raceTimeSpan(r4) == true) {
is_race_time = true;
race_num = 4;
} else if(ct > raceTimeSpan(r4) && ct < r5) {
next_race = r5;
} else if(raceTimeSpan(r5) == true) {
is_race_time = true;
race_num = 5;
} else if(ct > raceTimeSpan(r5) && ct < r6) {
next_race = r6;
} else if(raceTimeSpan(r6) == true) {
is_race_time = true;
race_num = 6;
} else if(ct > raceTimeSpan(r6) && ct < r7) {
next_race = r7;
} else if(raceTimeSpan(r7) == true) {
is_race_time = true;
race_num = 7;
} else if(ct > raceTimeSpan(r7) && ct < r8) {
next_race = r8;
} else if(raceTimeSpan(r8) == true) {
is_race_time = true;
race_num = 8;
} else if(ct > raceTimeSpan(r8) && ct < r9) {
next_race = r9;
} else if(raceTimeSpan(r9) == true) {
is_race_time = true;
race_num = 9;
} else if(ct > raceTimeSpan(r9)) {// If all races are finished
setDefaultText();
}
}
public function raceTimeSpan(d:Date):Boolean {
var race_mins:int = 2;
var race_on:Boolean = false;
var ct:Date = new Date();
if(ct.hours == d.hours) {
var max_mins:int = d.minutes + race_mins;
if(ct.minutes >= d.minutes && ct.minutes < max_mins) {
race_on = true;
}
}
return race_on;
}
public function setCountdown():void {
var hours_left:int = int(String(CustomDate.countdownTime(next_race)).split(":")[0]);
var mins_left:int = int(String(CustomDate.countdownTime(next_race)).split(":")[1]);
mins_left = (60*hours_left)+mins_left;
is_race_time = false;
if(mins_left > 2) {
race_ribbon.setText("NEXT RACE IN <font color='#000000' letterspacing='-1'>"+(mins_left+1)+" MINUTES</font>");
race_ribbon.setBG(0);
} else if(mins_left < 3) {
if((mins_left+1) <= 1) {
race_ribbon.setText("NEXT RACE IN <font color='#fdb913' letterspacing='-1'>"+(mins_left+1)+" MINUTE</font>");
} else {
race_ribbon.setText("NEXT RACE IN <font color='#fdb913' letterspacing='-1'>"+(mins_left+1)+" MINUTES</font>");
}
race_ribbon.setBG(1);
}
}
public function setDefaultText():void {
race_ribbon.setText("<font color='#fdb913' letterspacing='-1'>"+default_ribbon_text+"</font>");
race_ribbon.setBG(1);
}       
}
}

以防万一您不想单独浏览文件。种族功能区代码是

package com {
import flash.display.MovieClip;
import fl.motion.Color;
import flash.display.Sprite; 
import flash.text.*; 
public class RaceRibbon extends MovieClip {
private var c1:Color;
private var c2:Color;
public function RaceRibbon() {
c1 = new Color();
c1.setTint(0xfdb913,1);
c2 = new Color();
c2.setTint(0x000000,1);
}

public function setText(str:String=""):void {
str = str.toUpperCase();
this.tb.htmlText = str;
}
public function setBG(p:int=0):void {
switch(p){
case 0:
bg.transform.colorTransform = c1;
break;
case 1:
bg.transform.colorTransform = c2;
break;
}
}
}
}

我没有机会测试您的项目文件,而只是关于消除的建议:

要么手动触发setDefaultText();要么直接针对RaceRibbon 的 textField(因此只需注释//从显示的 3 行代码中剔除您未测试的其他两个)。

如果以下任何Update test可以正常工作以更新文本,那么您真正的问题在于:

  • IFfunction setCountdown():声明(if(mins_left > 2)之前trace ("minutes left: " + mins_left);对金额有什么看法?它看起来会变得> 2< 3+1 <= 1吗?如果没有,那么您的文本也不会更新。
  • function checkNextRace()(特别是如果您设置了next_race = null;那么肯定会遵循next_race = r1;应该给出调试器错误,例如"无法将值设置为空变量(不存在)">,但您说您没有错误,所以我很困惑为什么我的这样做。
    (使用ctrl+shift_+enter调试不是那个Test Movie选项)。

无论如何代码...

public function Generic() {
Mouse.hide();
// Set Race Ribbon
race_ribbon = new RaceRibbon;
race_ribbon.x = 1109; race_ribbon.y = 983;
// Update test #1
setDefaultText(); //did via Function work?
// Update test #2
race_ribbon.tb.htmlText = "testing123"; //did via Direct Targeting work?
race_ribbon.tb.htmlText = "<font color='#fdb913' letterspacing='-1'>" + "testing123" + "</font>"; //maybe works with HTML?
// Temp disable other code for above elimination tests    
/*
race_time_arr = [r1,r2,r3,r4,r5,r6,r7,r8,r9];
// Display Slideshow
ss = new ScreensaverSimple; ss.setScreensaver(screens);
// Make sure Hour of Power is not visible
HOP1.visible = false; HOP2.visible = false;
time_check_timer = new Timer(1000); 
time_check_timer.addEventListener(TimerEvent.TIMER, checkTime);
delay_add_timer = new Timer(1,1);
delay_add_timer.addEventListener(TimerEvent.TIMER, addAllChildren);
delay_add_timer.start();
*/  
}

相关内容

  • 没有找到相关文章

最新更新