05.09.08

ActionScript ReferenceError: Error #1056

Posted in Error, Error, errors, Flash, Flex at 6:08 am by Curtis J. Morley

ReferenceError: Error #1056: Cannot create property _x on flash.display.Sprite

or

ReferenceError: Error #1056: Cannot create property someVar on flash.text.TextField.

ActionScript 3 Error #1056 Description:
AS3 error 1056 appears when you have improperly referenced a property of an object. This will happen when you misspell something or when you reference variables in the AS2 fashion with a leading underscore ( _ ). AS3 error 1056 is actually pretty nice to work with because it tells you exactly what variable didn't work and it tells you which object it didn't work on.

You can also get this error if you try to dynamically assign a variable to an object that doesn't naturally accept one like a textField.  See Bad Code 3.

Flash / Flex Error 1056 Fix:
Simply spell the property correctly or make sure that you are using AS3 Syntax instead of AS2.


Bad Code 1:

var s = new Sprite();
s._x = 100;

Good Code 1:

var s = new Sprite();
s.x = 100;

Bad Code 2:

var t = new Timer(1000, 4);
t.dela = 500;

Good Code 2:

var t = new Timer(1000, 4);
t.delay = 500;

Bad Code 3:

myTextField.someVar = "something";

This should help you resolve Flex / Flash Error #1056

Thanks and as always Happy Flashing

Curtis J. Morley

Related ActionScript Error(s):
Flash / Flex Error 1119
- 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.
Flash / Flex Error 1151
Flash / Flex Error 1069
- This is the error you will get if you try and call a method with a misspelled name in the same way as calling a property with a misspelled name.

8 Comments »

  1. curtismorley.com » Flash CS3 / Flex 2 AS3 Error #1119 said,

    July 16, 2008 at 9:41 am

    [...] Errors: Flash / Flex Error 1056 – You will get AS3 Error 1056 instead of 1119 if you don’t properly type your object before [...]

  2. curtismorley.com said,

    July 16, 2008 at 10:28 am

    [...] 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 misspelled name in the same [...]

  3. Flash/ Flex Error « RIAdobe said,

    August 10, 2008 at 8:00 pm

    [...] 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 and call a property with a misspelled name in the same [...]

  4. David J McClelland said,

    February 22, 2009 at 8:55 am

    Here’s a variation: name a movieclip instance the same as the document class. Don’t declare that same instance in the document class.

    1056 cannot create property [instanceName] on [instanceName].

    Let the hair pulling begin : )

  5. curtismorley.com » Update to AS3 Reference Error #1056 said,

    March 17, 2009 at 1:12 am

    [...] added another description and scenario to AS3 Error 1056.  If you didn’t see your solution there before you may have the answer [...]

  6. Curtis J. Morley said,

    March 23, 2009 at 1:04 am

    Nice find David.

    Thanks for the comment.

    Curtis J. Morley

  7. Claude Needham said,

    October 28, 2009 at 2:46 pm

    I ran into the “ReferenceError: Error #1056: Cannot create property” error when trying to assign a Main class for use in my app.

    I named the “Document Class” as Main
    (this is found on the properties tab)

    In the as file I had the declarations correct:

    package {
    public class Main extends MovieClip {
    public function Main() {
    }
    }
    }

    But this silly thing continued to not work.

    Problem was the capitalization of the file.
    I changed file from main.as to Main.as and it worked just fine — error gone.

    As a windows programmer I typically don’t worry about upper or lower case. In fact, I usually make files as lowercase. Well Flash wants to see the same capitalization.

    Duh, I should have known. But is easy to miss.

    So just mentioning here in case that is your problem too. :)

  8. AlX said,

    December 7, 2009 at 8:22 am

    Here is another case where this error appears:

    When working with external libraries and using 2 (or more) external libraries that use the same component assets that are themselves imported from external libraries.

    When the code runs through the bad clip first, it tells:
    ReferenceError: Error #1056: Impossible to create the property __id0_ on (…)

    But if it runs through the good clip first, it all works…

Leave a Comment