Search code examples
arraysactionscript-3

Adding a movieclip in each square of my calendar (AS3)


I've got a calendar with squares in which each date is written:

var myArray:Array = new Array();
var row:Number = 0;
var moonNum:Number;
var holder_txt:MovieClip = new MovieClip;
addChild(holder_txt);
holder_txt.x = 35;
holder_txt.y = 10;
startDay -= 1;

    for (var t:int = 0; t < getDays(myDate); t++) {
    myArray[t] = (t+1);
    var textNum:String = myArray[t];
    import box;
    import moonPhase;
    var square:MovieClip = new box();
    var moon:MovieClip = new moonPhase();
    holder_txt.addChild(square);
    square.name = textNum
        moonNum= calculateMoonPhase(myDate.fullYear, myDate.month,t+1);
    
    square.texter.text = textNum +" "+ moonNum;
    
    
    square.x = (startDay) *75
    square.y = (row+1)*65
    startDay++;
        if(startDay >= 7){
            startDay = 0;
            row++;

I've got a function that calculate the moonPhase for everyday.

 moonNum= calculateMoonPhase(myDate.fullYear, myDate.month,t+1);

It results as a number (between 0 and 8).

I've got movieClip of a moon with 8 frames (new moon, full moon... etc.).

I'd like to add the movieClip of the moon on each square with the corresponding frame number.

moonClip.gotoAndStop(moonNum);

I've added each moonNum to each square day:

square.texter.text = textNum +" "+ moonNum;

But I've no idea how to add movieclips to each square day...

Any help?


Solution

  • It's better to add moonPhase in the class box directly. So for each box that you copied, you have an instance of moon in it to.

    But, in your sample code, you can add moon to the square directly to.

    square.addChild(moon);