1119: Access of possibly undefined property error in ActionScript 3
October 31, 2008
Most Popular | ActionScript3 | Flash

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 excellent article by Josh Tynjala.


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:

WHY DOESN'T THE "PARENT" PROPERTY WORK THE SAME IN ACTIONSCRIPT 3?


Ads by Google

Posted by ellen at October 31, 2008 02:55 PM

8 Comments

O-m-g!

Finally got it to work!! :D

One million thanks!

This was a big help. Thanks for posting!

Wow!! Thanks You, very very Much!! I was crazy with that error. Really works!!! God Bless You man.

Thank you so much for the help.

Been scratching my head for two days with stupid compiler errors and strange outputs.

Finally it works as it should thanks to this above.

Muito Bom. Obrigado

Thank you a lot,
I am taiwanese someone to looking for someway to solve error:1119, that is very useful for me.

You've reached the level of pure awesomeness!!!

Hi,

I am getting an error "1119: Access of possibly undefined property showCloseButton through a reference with static type NewTitleWindow".

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
import mx.containers.TitleWindow;
import mx.controls.Label;
public function showTitleWindow():void
{
var nTW:NewTitleWindow = new NewTitleWindow();
nTW.showCloseButton =true;
PopUpManager.addPopUp(nTW,this,true);
PopUpManager.centerPopUp(nTW);
}
]]>
</mx:Script>
<mx:Button label="Click Me !" click="showTitleWindow();" horizontalCenter="0" verticalCenter="0"/>
</mx:Application>

How to solve this error? please help me


Ads by Google

 RSS   |   Contact Me

Ads by Google

Ads by Google