Flash CS3 / Flex 2 AS3 Error #1119

Error #1119:
Access of possibly undefined property buttonText through a reference with static type flash.display:SimpleButton

or

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

Description:
This means that you are trying to change dynamic text nested inside a button. This is a simple fix. Just change the button to a movieClip.

Another more prevalent reason that you will get ActionScript Error #1119 is because the the new way Flash/flex handles parent objects has changed. In AS2 parent.myVar would work just fine. In ActionScript3 the compiler doesn’t know what the parent is unless specifically typed or casted instead it chalks everything up to DisplayObjectContainer. This means that it doesn’t know that the ‘parent’ is a MovieClip. The reason for this is because you can now change the object from one displayObject to another easily at compile time. You could change the parent object from a MovieClip to SimpleButton at compile time.

You also want to check your syntax to make sure that you have dynamically targeted an object correctly. For example, if you are trying to use AS3 to target a series of movieClips dynamically and each of the names start with ‘card’ and have a sequential value as well then you must use the code in Fix3 to prevent AS3 Error #1119. Fix #4 is similar to Fix 3 but Fix 4 is specific to the DisplayObject.
Fix 1:
You need to cast the parent as the type that you want or you need.

myTextField.text = MovieClip(this.parent).someVar
or
myTextField.text = (this.parent as MovieClip).someVar

One of the best explanations of casting for this error is written up by Josh Tynjala go visit his blog called “Why doesn’t the ‘parent’ property work the same in ActionScript 3”

.

Fix 2:
Rather than looking outside the movie for the variable you can push the variable into the child movieClip and then access it within itself. For example if I have a movieClip named bob that is inside of a clip named joe then I would have Joe push the variable into bob and bob would access it within himself and not need to ask his parent for the variable because he already has it.

From Joe

bob.someVar = “This is the variable”;

From Bob

myTextField.text = someVar;

Fix 3:

Bad Code:

this.card[i].id = “something”;

Good Code:

this[“card”+i].id = “something;

Fix 4:
The good code below uses a direct reference to the object that holds the property someProperty. Whereas the Bad Code example is trying to access the property through a reference through the displayObject. Because the displayObject doesn’t have the property it cannot change it.

Bad Code:

this.getChildByName(‘card’+_setClicksCounter).someProperty = true;

Good Code:

this[“card”+_setClicksCounter].someProperty = true;

Fix 5:
1119: Access of possibly undefined property nestedMovieClip through a reference with static type Class.
This is easy to fix. It just means that you are trying to access a nested object within the class statement rather than from within the Class. The problem is that the keyword “this” in the first example doesn’t references the Class itself rather the object the Class is linked to.

Bad Code:

package com.cjm.sound
{
public class SoundControl extends MovieClip
{
var _progwidth:uint = this.progBar.width;
public function SoundControl (url=null):void
{
doSomething();
}}}

Good Code:

package com.cjm.sound
{
import flash.display.MovieClip;
public class SoundControl extends MovieClip
{
var _progwidth:uint;
public function SoundControl ():void
{
_progwidth = this.progBar.width;
}}}

Related Errors:
Flash / Flex Error 1056 – You will get AS3 Error 1056 instead of 1119 if you don’t properly type your object before referencing a property on it. For example var s:Sprite = new Sprite(); s._x = 10; will give error 1119 but var s = new Sprite(); s._x = 10; will give Error 1056.

As always – Happy Flashing