Hi!
I have this simple piece of code below:
Code:
function createShapes():void
{
var X:int=50;
var Y:int=55;
for(var i:int=0;i<35;i++)
{
var shape:MovieClip = new numberBox_mc();
shape.x = X;
shape.y = Y;
shape.eatNumber.text = "";
shape.name = "shape"+i;
addChildAt(shape, i);
X+=60;
if (X == 410)
{
X=50;
Y+=60;
}
}
}
function feedShapes():void
{
for(var i:int=0;i<35;i++)
{
var myshape:DisplayObject = getChildByName("shape"+i);
// error happens in the next line of code
myshape.eatNumber.text = String(i);
}
}
The compiler keep spiting out the following error message:
1119: Access of possibly undefined property eatNumber through a reference with static type flash . display : DisplayObject .
What really annoys me is the 'possibly' word within the message. It doesnt make any sense to me and sounds as if the compiler would be trying to guess things. Doesnt it at least seems to be obvious enough that this code will be ran against one or more mcs that will be created at run time - and therefore doesnt exist YET? What if I would be creating it totally from scratch, programatically????
Anyway, how to turnaround this odd behavior?
PS: Yes, I have the 'numberBox_mc' mc at the library!