Jump to content


Date Script assistance ...


  • You cannot reply to this topic
No replies to this topic

#1 Flash-newbie

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 22 March 2008 - 06:13 AM

I have a .swf file created with Flash CS3 , but admittedly, my knowledge of AS3 .0 is in its infancy and I think the problem may lye there. I would like the top, middle and bottom line days to automatically update, but they are not. Here is the test page holding the .swf file. Here is the AS 3.0 code:

// Action script...

// [Action in Frame 1]
Stage.scaleMode = "noScale";
Stage.showMenu = false;
timeclock_class = function ()
{
    var obj = this;
    var day_arr = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
    var month_arr = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    var time_str = "";
    var date_str = "";
    var am_pm_str = "";
    var hour_str = "";
    var min_str = "";
    var interval_id;
    this.date = new Date();
    this.isLeapYear = function ()
    {
        if (obj.date.getFullYear() % 4 == 0)
        {
            switch (true)
            {
                case obj.date.getMonth() < 1:
                {
                    return (false);
                    break;
                } 
                case obj.date.getMonth() > 1:
                {
                    return (true);
                    break;
                } 
                case obj.date.getMonth() == 1:
                {
                    if (obj.date.getDate() >= 29)
                    {
                        return (true);
                    }
                    else
                    {
                        return (false);
                    } // end else if
                    break;
                } 
            } // End of switch
        } // end if
        return (false);
    };
    this.getDaySuffix = function ()
    {
        var suffix = "";
        var _loc1 = obj.getElapsedDays().toString();
        if (_loc1.charAt(_loc1.length - 2) == "1")
        {
            return ("th");

        }
        else if (_loc1.charAt(_loc1.length - 1) == "1")
        {
            return ("st");

        }
        else if (_loc1.charAt(_loc1.length - 1) == "2")
        {
            return ("nd");

        }
        else if (_loc1.charAt(_loc1.length - 1) == "3")
        {
            return ("rd");

        }
        else
        {
            return ("th");
        } // end else if
    };
    this.getElapsedDays = function ()
    {
        var dayOfMonth = obj.date.getDate();
        var _loc3 = obj.date.getMonth();
        var _loc2 = 0;
        for (var _loc1 = 0; _loc1 < _loc3; ++_loc1)
        {
            _loc2 = _loc2 + daysInMonth[_loc1];
        } // end of for
        if (obj.isLeapYear() == true)
        {
            _loc2 = _loc2 + 1;
        } // end if
        _loc2 = _loc2 + dayOfMonth;
        return (_loc2);
    };
    this.getDaysOfYear = function ()
    {
        if (obj.date.getFullYear() % 4 == 0)
        {
            return (366);
        }
        else
        {
            return (365);
        } // end else if
    };
    this.getWeekNumber = function ()
    {
        var _loc2;
        var week_num;
        var dateOfJan1 = new Date(obj.date.getFullYear(), 0, 1);
        var _loc1 = dateOfJan1.getDay();
        switch (true)
        {
            case _loc1 == 0:
            {
                _loc2 = 1;
                break;
            } 
            case _loc1 == 1:
            {
                _loc2 = 0;
                break;
            } 
            case _loc1 > 1:
            {
                _loc2 = 8 - _loc1;
                break;
            } 
        } // End of switch
        var _loc3 = obj.elapsedDays - _loc2;
        if (_loc3 < 1)
        {
            week_num = 52;
        }
        else
        {
            week_num = Math.ceil(_loc3 / 7);
        } // end else if
        return (week_num);
    };
    this.update = function ()
    {
        obj.date = new Date();
        obj.dayOfWeek = day_arr[obj.date.getDay()];
        obj.elapsedDays = obj.getElapsedDays();
        obj.month_str = month_arr[obj.date.getMonth()];
        obj.daySuffix = obj.getDaySuffix();
        obj.daysLeft = obj.getDaysOfYear() - obj.elapsedDays;
        obj.weekNum = obj.getWeekNumber();
    };
};
var grey_tf = new TextFormat();
grey_tf.color = 10066329;
var orange_tf = new TextFormat();
orange_tf.color = 14448640;
timeclock = new timetimeclock_class();
timeclock.update();
this.date_txt.text = timeclock.dayOfWeek;
this.date_txt.text = this.date_txt.text + timeclock.date.getDate();
this.date_txt.setTextFormat(2, 4, orange_tf);
this.month_txt.text = timeclock.month_str + " " + timeclock.date.getFullYear();
this.dayOfYear_txt.text = timeclock.elapsedDays + "" + timeclock.daySuffix + " Day | ";
var sec1 = this.dayOfYear_txt.text.length - 3;
this.dayOfYear_txt.text = this.dayOfYear_txt.text + (timeclock.daysLeft + " Days Left | ");
var sec2 = this.dayOfYear_txt.text.length - 3;
this.dayOfYear_txt.text = this.dayOfYear_txt.text + ("Week " + timeclock.weekNum);
this.dayOfYear_txt.setTextFormat(sec1, sec1 + 3, orange_tf);
this.dayOfYear_txt.setTextFormat(sec2, sec2 + 3, orange_tf);

Given my newbie status to Flash, any assistance in where the problem may be would be greatly appreciated.

Edited by Flash-newbie, 22 March 2008 - 07:49 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users