06.13.07

Flash CS3 / Flex 2 AS3 Error #1119

Posted in errors, Flash at 7:32 am by Curtis J. Morley

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

17 Comments »

  1. curtismorley.com » Blog Archive » Added new info to Error #1119 said,

    August 15, 2007 at 6:42 pm

    […] http://curtismorley.com/2007/06/13/flash-cs3-flex-2-as3-error-1119/ […]

  2. Jens said,

    October 27, 2007 at 3:15 am

    It does not always mean that. I’m not doing anything with movies and I see this in Flex 2 when trying to compile. The scope of variables seems to be hard to make sense out of in Flex, declaring them does not always help anything.

  3. Curtis J. Morley said,

    October 29, 2007 at 5:08 pm

    Jens which fix are you talking about specifically. I believe that you are talking about Fix #1 for error 1119. This is a generic error and will be displayed in a number of scenarios. If you are getting this error it means that Flex, in your case, doesn’t recognize the property and it shows up as undefined. This means that it is either not there, not there yet (meaning that the order of operation hasn’t executed the property that you are trying to access), or you are incorrectly accessing the property. Let me know a few more details and I am sure that I can help you out.

    Thanks,

    Curtis J. Morley

  4. Q4 « Programming Sustainability said,

    November 14, 2007 at 12:13 pm

    […] I am getting a1119 error when adding event listeners for a custom event class with multiple types. I have tried everything, […]

  5. jon said,

    December 19, 2007 at 9:56 am

    This is a rubbish error message that has no basis in reality.

    My variable is declared as a class variable, in perfect scope.
    I am using it in a timer event which increments the variable with no
    problem. When I try and display it in the same function, it complains
    that it is “possibly” undefined even though it has just modified it.

    Wonder if Silverlight has these problems.

  6. Curtis J. Morley said,

    December 19, 2007 at 6:34 pm

    jon,

    Sorry you are so frustrated. I can sympathize. If your variable is a member variable, it should persist throughout any method within that class. Here is what I would suggest. I would look for something in the code that removes the variable or sets it to null. I would also throw in a trace statement that traces out variable and move it around until you find out where the variable is missing. Don’t forget to use your break points. They are awesome for debugging.

    I would be happy to look at your code. Just post it here.

    Thanks and Happy Flashing.

    Curtis J. Morley

  7. curtismorley.com » Added More Info to ActionScript Error #1119 said,

    February 10, 2008 at 6:51 am

    […] I added Fix #5 to ActionScript Error #1119  This fix is specific to people assigning  classes to movieClip Objects in the library from […]

  8. curtismorley.com » Search Engine Optimization Example said,

    June 2, 2008 at 5:35 pm

    […] Flash CS3 Error 1119 – #1,2 hit on Google […]

  9. Mathew said,

    June 10, 2008 at 10:26 pm

    Great info. Thanks.

    I’d like to add my problem and the solution that was found for it.

    I’m setting up a swf that will display some balls on the screen. These balls will pulse in and out. When the user mouse over the ball it will grow and display some hidden text. The balls are then dragable. To add better functionality to the display i wanted to make sure that the ball only ballons out and contracts at the full extent of the balls size, otherwise the ball will start from the start of the label. So i set three labels in the ball MC, “waiting”, “active” and “out”. At the end of “active” label i put some code to change a string value (the string value is tested in the main time line):-

    moveToOut = “out”;

    which i set in the main time line –

    moveToOut = “”;

    I tried parent, parent.parent, root and this only to get the same error this article is about. The solution works as below

    (root as MovieClip).moveToOut = “out”;

    Now it’s great that this works, but i’m a bit confused as to why. Since my variable is a String. What is being changed here?

  10. Phillip Kerman said,

    July 15, 2008 at 5:12 pm

    Another “good” way to get this error to pop up:
    draw a dynamic text field onstage…give it an instance name.
    put text input on stage–with the same instance name.
    publish, and enjoy the cryptic message

  11. Curtis J. Morley said,

    July 15, 2008 at 7:01 pm

    Phillip,

    Thanks, this is great and I will add this example to the ones above. Good luck at Flash Forward. I’m sure your presentation will be great.

    Thanks,

    Curtis J. Morley

  12. curtismorley.com » ReferenceError: Error #1069: Property addEvent not found on flash.utils.Timer and there is no default value. said,

    July 16, 2008 at 10:25 am

    […] 1061 but var t = new Timer(1000, 60); t.addEvent(TimerEvent.TIMER, Tick); will give Error 1069. Flash / Flex Error 1119 Flash / Flex Error 1056 – This is the error you will get if you try and call a method with a […]

  13. Flash/ Flex Error « RIAdobe said,

    August 10, 2008 at 8:01 pm

    […] 1061 but var t = new Timer(1000, 60); t.addEvent(TimerEvent.TIMER, Tick); will give Error 1069. Flash / Flex Error 1119 – The dreaded AS 3 Error 1119 Flash / Flex Error 1056 – This is the error you will get if you try […]

  14. Arun said,

    June 17, 2009 at 5:14 am

    i get this error as follows:

    Severity and Description Path Resource Location Creation Time Id
    1119: Access of possibly undefined property CustomerTypeID through a reference with static type Number. Best Quote/src/WebService webService.as line 59 1245240864810 5817

    for the following code:

    package WebService
    {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.*;

    /* import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.soap.LoadEvent;
    import mx.rpc.soap.WebService; */

    public class webService extends Sprite
    {
    public function webService()
    {
    super();
    var ur:URLRequest=new URLRequest(“http://sreejith/bestquote/services/bestQuoteAdmin.asmx/getCustomerType”);
    var ul:URLLoader=new URLLoader();
    ul.dataFormat=URLLoaderDataFormat.TEXT;
    ul.addEventListener(Event.COMPLETE,eventLoad);
    try{
    ul.load(ur);
    }
    catch (error:Error)
    {
    trace(“Unable to load URL: ” + error);
    }

    sendToGrid();

    }

    public function eventLoad(event:Event):void
    {
    //trace(event.result);

    var recordArray:Array=new Array;
    var z:XML;
    var i:int;
    var loader:URLLoader = URLLoader(event.target);
    //trace(event.target);
    var xml:String=loader.data;
    z=XML(loader.data);

    trace(“Customer details”);
    for(i=0;i<2;i++)
    {

    trace(” Customer ID is “+z..CustomerTypeID[i]+” and Customer Type is “+z..TypeName[i]);

    }

    }
    public function get(obj:Array=null):Array
    {

    obj=new Array;
    obj.push(z..CustomerTypeID[0]) ;
    trace(obj);
    return obj;
    }
    /* var appXml = new DOMParser();
    var xmlobject = appXml.parseFromString(event.target.data, “text/xml”);
    air.trace(“Connection Status=”+Status);
    var Status = GetXMLNodeValue( xmlobject, ‘Status’)
    if (Status == 1)
    {
    Company_ID = parseInt(GetXMLNodeValue(xmlobject, ‘Company_Id’));

    }
    */

    public function sendToGrid():void
    {

    }

    }
    }

  15. Arun said,

    June 17, 2009 at 5:16 am

    what may be the reason…i really need to get around it….help any is appreciated

  16. Jesusinni said,

    August 11, 2009 at 11:02 am

    Thanks for this post, i found it really interesting and helpful, i wish i read this a week ago lol.

  17. as3 _parent | Born2Design said,

    March 6, 2010 at 5:17 pm

    […] Great articles that explain it all: http://www.zeuslabs.us/2007/07/12/disabling-actionscript-3-strict-mode-in-flash-cs3/ http://curtismorley.com/2007/06/13/flash-cs3-flex-2-as3-error-1119/ […]

Leave a Comment