1119: Access of possibly undefined property error in ActionScript 3

I am working on a Flash project where a MovieClip that is contained within another clip needs to get a property from the main timeline of the container clip.


trace(this.parent.someProperty)


But this generated an error:

1119: Access of possibly undefined property someProperty through a reference with static type flash.display:DisplayObjectContainer.

I finally found the reason for this in this

The problem is with “casting”. The parent clip must be cast as type “MovieClip” or the compiler will throw that error in strict mode.

Either of the following two methods will work:


MovieClip(this.parent.someProperty);

or


(this.parent as MovieClip).someProperty;

For the complete explanation of why this is so, see: