Perhaps I don't understand classes

I started building a custom calendar in flash and found that as I expanded I really just needed to move it out of frame 1 and into a class. I think I’m missing a fundamental connection between my project, the class at the symbols I reference because every error I fix or remove the code just to move on brings more errors.

The project is meant to have a few static elements on the project stage (days of the week, buttons to change month, and a dynamic text box for the month/year) while dynamically adding the spaces for each day of the month depending on the month, year and whether an event is planned that day.

My class called “Calendar” is reference as my Document Class for project “calendar” as below


package {
    
    import flash.display.MovieClip;
    
    public class Calendar extends MovieClip {
        
        //------------Consturctor------------
        public function Calendar():void {
            SetInitialCalendar();
        }

        //------------Properties------------
        public var currentDate:Date;    //today's current date
        public var calYear:Number;    //the year for the current calendar view
        public var calNumMonth:Number;    //the number of the month for the current calendar view (0-11)
        public var calStrMonth:String;    //the string of the month for the current calendar view (January-December)
        
        public var numberOfDays:Number;    //number of days in the current month
        public var startOfMonth:Number;        //starting day of the current month (1-7)
        
        public var currentDayCt:Number;    //current number of day for sPiece being placed
        public var xLoc:Number;        //current X position for sPiece being placed
        public var yLoc:Number;        //current Y position for sPiece being placed
        
        public var datesArray:Array = new Array();    //holds all sPiece objects
        public var eventDatesArray:Array = new Array(); //holds all sPice objects with events planned
        
        //Need to dynamically fill these values
        public var eventsArray:Array = new Array(19, 12, 9, 8, 6, 1);
        public var eventTextArray:Array = new Array("Golf Tournament at Fairways", "Comedy Show at the Some Long Title", "Equine show", "Equine show", "Some other event goes here", "Another event goes here that's longer");
        
        public var sPiece;    //object of SpacePiece or SpacePiecePlanned being created
        
        //------------Methods------------
        public function SetInitialCalendar():void {

            //Set Initial Property values
            currentDate = new Date();
            calYear = currentDate.getFullYear();
            calNumMonth = currentDate.getMonth();
            
            calStrMonth = DetermineMonth(calNumMonth);
            numberOfDays = DetermineNoDays(currentDate.getMonth());
            startOfMonth = DetermineStartDay(calNumMonth+1, calYear);
            
            currentDayCt = 1;
            xLoc = 20;
            yLoc = 78;
            
            //Build initial calendar
            BuildCalendar();
        }
        
        public function DetermineMonth (numberMonth:Number) {    //return the string month corresponding to the number of the month (0-11)
            if (numberMonth == 0) {return "January";}
            if (numberMonth == 1) {return "February";}
            if (numberMonth == 2) {return "March";}
            if (numberMonth == 3) {return "April";}
            if (numberMonth == 4) {return "May";}
            if (numberMonth == 5) {return "June";}
            if (numberMonth == 6) {return "July";}
            if (numberMonth == 7) {return "August";}
            if (numberMonth == 8) {return "September";}
            if (numberMonth == 9) {return "October";}
            if (numberMonth == 10) {return "November";}
            if (numberMonth == 11) {return "December";}
        }
        
//need to add leap year determination to this function        
        function DetermineNoDays (numberMonth:Number) {        //return the number of days corresponding to the number of the month (0-11)
            if (numberMonth == 0) {return 31;}
            if (numberMonth == 1) {return 28;}
            if (numberMonth == 2) {return 31;}
            if (numberMonth == 3) {return 30;}
            if (numberMonth == 4) {return 31;}
            if (numberMonth == 5) {return 30;}
            if (numberMonth == 6) {return 31;}
            if (numberMonth == 7) {return 31;}
            if (numberMonth == 8) {return 30;}
            if (numberMonth == 9) {return 31;}
            if (numberMonth == 10) {return 30;}
            if (numberMonth == 11) {return 31;}
        }
        
        function DetermineStartDay (numberMonth:Number, year:Number):Number {    //return the day of the week the month starts on (1-7)
            var tempDate:Date = new Date(year, numberMonth, 1);
            return tempDate.getDay() + 1;
        }
        
        function BuildCalendar():void {        //build calendar based on calendar properties
            for (var i=1;i<=6;i++) {
                for (var j=1;j<=7;j++) {
                    if (j >= startOfMonth || i > 1) {
                        var temp = eventsArray.pop();
                        if (currentDayCt == temp) {
                            sPiece = new SpacePiecePlanned();
                            eventDatesArray.push(sPiece);
                            sPiece.eventText.text = eventTextArray.pop();
                        }
                        else {
                            eventsArray.push(temp);
                            sPiece = new SpacePiece();
                        }
                    }
                    else {
                        sPiece = new SpacePiece();
                    }
            
                    sPiece.x = xLoc;
                    sPiece.y = yLoc;
            
                    if (currentDayCt <= numberOfDays && (j >= startOfMonth || i > 1)) {
                        sPiece.dateOfMonth.text = currentDayCt;
                        datesArray.push(sPiece);
                        currentDayCt++;
                    }
            
                    this.addChild(sPiece);
            
                    xLoc += 102;
                }
                if (currentDayCt > numberOfDays) {
                    break;
                }
            
                xLoc = 20;
                yLoc += 72;
            }
        }
        
        function MonthText() {    //return Month and Year to set as text
            return calStrMonth + " " + calYear;
        }
    }
}

Most was pulled directly from frame 1 and reorganized to be clearer. Before making the class my Document Class and just importing it, I really had a problem with addChild(sPiece) but it seems to have moved on to other errors now.

In my calendar project I have 2 symbols (MovieClips) which are exported as follows
SpacePiece- Class: SpacePiece, BaseClass:Calendar, Export for ActionScript checked and Export for frame1 checked
SpacePiecePlanned- same as above except Class: SpacePiecePlanned

I changed from BaseClass flash.display.MovieClip to Calendar mostly just to see if it helped, it didn’t…

SpacePiecePlanned has a little code within it on frame 1 (is that bad?? I get a lot of override errors, even when the code is commented out):


stop();

this.addEventListener(MouseEvent.ROLL_OVER, over);
this.addEventListener(MouseEvent.ROLL_OUT, out);

function over(evt:MouseEvent):void {
    this.gotoAndStop(2);
}

function out(evt:MouseEvent):void {
    this.gotoAndStop(1);
}

this is to change the color on mouse rollover

Lastly I have a bit of code in my project, frame 1 to initialize the class and add function to a close button.


import flash.external.*;
closeBtn.addEventListener(MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void {
    ExternalInterface.call("HideOverlay");
}

var myCal = new Calendar();
addChild(myCal);
this.month_year.text = myCal.calStrMonth + " " + myCal.calYear;

So that’s about it…

Currently I’m getting override errors on anything in SpacePiecePlanned and when I just remove all code it gives me:

Type was not found or was not a compile-time constant: MouseEvent
getFullYear is not a recognized method of the dynamic class Date
getMonth…
getDay…

I am running CS4, actionscript 3.0. Lastly I haven’t programmed using classes and what not in many years so I’m sure this is going to be messy.

Also, thanks for helping