ACTIONSCRIPT2- coding

Hi Experts,

here's the scenario: coding in AS2, trying to make a calendar. I create the date-cells using the following code:

var i:Number;
var allcells:Array = new Array();
for (i=0; i<42; i++)
 {
  var currCell = this.createTextField("cell" + i,this.getNextHighestDepth(),xoff,yoff,18,18);
  currCell.background=true;
  currCell.backgroundColor=0x99CCFF;
  currCell.border=true;
  currCell.borderColor=0x9999CC;
  currCell.selectable=false;
  currCell.width = 18;
  currCell.height = 18;
  currCell.setTextFormat(cellformat);
  currCell._x=xoff+(22*(i-(Math.floor(i/7)*7)));
  currCell._y=yoff+(22*Math.floor(i/7));
  allcells.push(currCell);
}

Open in new window


So far so good. After doing the computations to fill the cells with the appropriate dates, i need to be able to select a date from a specific cell. In order to check the mouse coords against cells coords i need to read each cell and then reading ._xmouse and .ymouse properties. Here i got stuck. this is the code i use, but it doesnt work. It supposed to change the background color of the selected cell.

var m_listener:Object = new Object();
var cell_name:Object= new Object();
m_listener.onMouseUp = function()
  {
    for (i=0; i<42; i++)
     {
       cell_name=currCell[i];
       xm=cell_name._xmouse;
       ym=cell_name._ymouse;
     
       if (xm>0 && xm<18 && ym>0 && ym<18)
        {
         cell_name.backgroundColor=0xff9999;
        }
     }  
  }
Mouse.addListener(m_listener);

Open in new window


Any help in this matter will be apreciated.

Thank you in advance.
Regards
Raul
raulmondaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Antonio EstradaTech Leader / Senior Web DeveloperCommented:
There's a small error in your code on the listeners, it should be this:

var m_listener:Object = new Object();
var cell_name:Object= new Object();
m_listener.onMouseUp = function()
  {
    for (i=0; i<42; i++)
     {
       cell_name=allcells[i];
       xm=cell_name._xmouse;
       ym=cell_name._ymouse;
     
       if (xm>0 && xm<18 && ym>0 && ym<18)
        {
         cell_name.backgroundColor=0xff9999;
        }
     }  
  }
Mouse.addListener(m_listener);

Open in new window


You were calling "currCell" which is an undefined object in the scope of the function, and instead should call "allcells" which is a global array that keeps a reference of each cell.

Good luck!

-V
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
raulmondaAuthor Commented:
Thank you. It works :)

Regards,
Raul
0
Antonio EstradaTech Leader / Senior Web DeveloperCommented:
Glad to help! :)

-V
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.