1

Here's the link to the whole project including all the dependencies if needed. https://www.dropbox.com/sh/3d3towtkhb4c38r/AADdxDJq9ix7bK9hTkt_VTSAa?dl=0

Basically trying to clean up some script I was left to deal with and have been banging my head against the wall as to why this isn't working. I don't get any debug errors, everything seems to be linked where it needs to be linked. My font seems to be embedded, all my instance names seem to be right... the only thing I can think of is I'm missing something silly in the code. Any help would be really appreciated! Nothing like being left a mess and having to fix it.

Basically the text box is supposed to have a countdown timer based on what race is approaching (e.g Race X is in xxx minutes) and If there isn't a race approaching, it should show some default text. At the moment, It doesn't seem to want to change the dynamic text at all!

EDIT: I'll also mention the RaceRibbon Movieclip that the text is contained in is also exported for as3 to the com.RaceRibbon class.

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);
        }       

    }

}

And just in case you don't want to go through the files individually the com.RaceRibbon code is

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;
            }
        }

    }

}
  • Just a wild guess, ribbon's (x,y) are ~ (1100,980) which is offscreen (unless it is a no-scale fullscreen). – Organis Apr 20 '17 at 23:58
  • The file is 1920x1080 so unless I'm mistaken (I'm very happy to be mistaken, that should be bottom right hand corner if i'm not mistaken? The ribbon itself is being displayed (the movieclip that the text is contained in), the text just isn't being modified. – LeighPierce90 Apr 21 '17 at 00:09
  • Well, I don't see **tb** declared or created, so there are a number of possibilities. For now I advise to **trace(describeType(this));** in **RaceRibbon** constructor, as well as trace a list of all children with their **name** property and **getQualifiedClassName(...)** to learn the exact classes they belong to. – Organis Apr 21 '17 at 02:17
  • When i try to trace i get the below code. tb is already on the timeline so shouldn't need anything else unless I'm mistaken? `TypeError: Error #1009: Cannot access a property or method of a null object reference. at Generic/setDatesToCurrent() at Generic/checkTime() at Generic/addAllChildren() at flash.utils::Timer/_timerDispatch() at flash.utils::Timer/tick()` – LeighPierce90 Apr 21 '17 at 04:11
  • File > Publish Settings > Permit Debugging to learn the number of the line that gives you that error. About " shouldn't need anything else": you can have duplicates, or wrong object type, or something else. Basically, declaring it in the class deliberately as **public var tb:TextField;** won't hurt and a generally good practice of working with designed instances. – Organis Apr 21 '17 at 08:05

1 Answers1

1

I've not had a chance to test your project files but just a suggestion on elimination :

Either manually trigger setDefaultText(); or else directly target the RaceRibbon's textField (so just comment // out the other two you aren't testing from those shown 3 lines of code).

If any Update test below work correctly to update text then your true problem lies in either :

  • IF statement of function setCountdown():(before if(mins_left > 2) what does trace ("minutes left: " + mins_left); say about the amount? Does it look like it could ever become > 2 or < 3 or +1 <= 1? If not, then your text will not update either.)
  • or function checkNextRace() (especially if you set next_race = null; then surely following that with next_race = r1; should give a debugger error like "Cannot set a value to a variable that is NULL (non-existent)" but you said you got no errors so I'm confused why mine does that.
    (use ctrl+shift_+enter to debug not that Test Movie option).

Anyways the code...

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();
    */  
}
VC.One
  • 14,790
  • 4
  • 25
  • 57
  • 1
    Ok... so debug console led me to a line of code that I didn't think was doing anything (it wasn't... aside from breaking every subsequent code!!!) I tried the other codes and it actually made the ribbons disappear! When i deleted the lines, everything came back and started working. I feel really quite foolish because I should have done that first, I think I thought I did and never checked it again but you got me back on track and got me out of a lot of trouble!!! Thank you so much again! – LeighPierce90 Apr 22 '17 at 06:08