This is a function in a movieclip called Level
function makeLvl():void
{//this function will add bells to the stage
bellTime ++;//increment the time
if(bellTime >= bellLimit)
{//if the time for bell creation has been reached
bellTotal ++;//increase the amount of bells created
var newBell:Bell = new Bell();//create a new bell instance
this.addChild(newBell);//and add it to bellHolder
bellTime = 0;//reset the time for another creation
bells.push(newBell);
}
}
this creates a few children movieclips inside Level.
Now, inside Bell(), I wish to access some variables like this:
parent.bellTotal = 0;
but it says:
Access of possibly undefined property bellTotal through a reference with a static type flash:DisplayObjectContainer
what is this error and why is it stopping my code from working? Thank you
From within your Bell class, try casting parent as a MovieClip, something like:
or
Also I would make sure
bellTotalis declared at the parent’s scope, outside of themakeLvl()function.I don’t see the whole picture with what you are doing, but alternatively you can add a function/variable to the Bell class, and within
makeLvl()pass or set a value.For good measure, you might want to also check if MovieClip(parent) == null before accessing any of its properties