Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Can't get dynamic text to update.

Community Beginner ,
Apr 20, 2017 Apr 20, 2017

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! I've tried traceing and it just gives me errors. So I'm at a total loss as of now...

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

Generic.as

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.fullYear = cd.fullYear;

                arr.month = cd.month;

                arr.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>");

          

        }

    }

}

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

com.RaceRibbon.as

package com {

    import flash.display.MovieClip;

    import fl.motion.Color;

    import flash.display.Sprite;

    import flash.text.*;

    import flash.utils.*;

  

    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;

            }

        }

    }

}

TOPICS
ActionScript
475
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 21, 2017 Apr 21, 2017

is Generic your document class?

what error do you see when trying to use trace()?

Translate
Community Expert ,
Apr 21, 2017 Apr 21, 2017

is Generic your document class?

what error do you see when trying to use trace()?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 21, 2017 Apr 21, 2017

Hey @kglad

Yup, Generic is my document class (the "hour of power" is working, just not the dynamic text)

When i try to trace ANYTHING i get

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()


But i don't get those errors when I don't trace.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 21, 2017 Apr 21, 2017

Trace led me the right direction! Eventually found the debug console and led me to a line of code that was breaking everything!

Thank you so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 22, 2017 Apr 22, 2017
LATEST

your welcome.

p.s. for problems that generate an error click file>publish settings>swf>tick 'permit debugging' and retest. the problematic line number will be in the error message.  then use trace to pinpoint the problematic reference in that line of code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines