ReferenceError: Error #1056: Caused by Declaring Stage Instances Private
If you declare a stage instance private you get the message: "ReferenceError #1056 Cannot create property my_mc on StageIntanceDeclarationsClass"
This error occurs when you uncheck the "Declare Stage Instances Automatically" checkbox in the "ActionScript 3.0 Settings" dialogbox and proceed to declare stage instances as private variables in the class associated with the containing MovieClip.
A Note on Inheritances and Declaring Stage Instances:
You cannot choose to simply always declare stage instances automatically without forging the use of inheritance in classes linked to MovieClip Symbols. If you have a class APrime which is derived from class A and APrime is linked to a MovieClip Symbol, all stage instances used in the base class A must be manually declared in class A. "Declare Stage Instances Automatically" only declares instances in the class linked to the MovieClip Symbol and does NOT make those references available to any base classes.
Example:
Assume that the class StageIntanceDeclarations is set as the class associated with a MovieClip which c0ntains the MovieClip my_mc. Then the following code will cause ReferenceError #1056 at runtime.
The output is as follows:
ReferenceError: Error #1056: Cannot create property my_mc on StageIntanceDeclarations.
at flash.display::Sprite/flash.display:Sprite::constructChildren()
at flash.display::Sprite$iinit()
at flash.display::MovieClip$iinit()
at TestStageIntanceDeclarationsBase$iinit()
at flash.display::Sprite/flash.display:Sprite::constructChildren()
at flash.display::Sprite$iinit()
at flash.display::MovieClip$iinit()
To avoid this error simply declare my_mc as public:
public var my_mc:MovieClip;
This error occurs when you uncheck the "Declare Stage Instances Automatically" checkbox in the "ActionScript 3.0 Settings" dialogbox and proceed to declare stage instances as private variables in the class associated with the containing MovieClip.
A Note on Inheritances and Declaring Stage Instances:
You cannot choose to simply always declare stage instances automatically without forging the use of inheritance in classes linked to MovieClip Symbols. If you have a class APrime which is derived from class A and APrime is linked to a MovieClip Symbol, all stage instances used in the base class A must be manually declared in class A. "Declare Stage Instances Automatically" only declares instances in the class linked to the MovieClip Symbol and does NOT make those references available to any base classes.
Example:
Assume that the class StageIntanceDeclarations is set as the class associated with a MovieClip which c0ntains the MovieClip my_mc. Then the following code will cause ReferenceError #1056 at runtime.
package
{
import flash.display.MovieClip;
public class StageIntanceDeclarations extends MovieClip
{
//Private Causes ReferenceError #1056
private var my_mc:MovieClip;
function StageIntanceDeclarations()
{
}
}
}
The output is as follows:
ReferenceError: Error #1056: Cannot create property my_mc on StageIntanceDeclarations.
at flash.display::Sprite/flash.display:Sprite::constructChildren()
at flash.display::Sprite$iinit()
at flash.display::MovieClip$iinit()
at TestStageIntanceDeclarationsBase$iinit()
at flash.display::Sprite/flash.display:Sprite::constructChildren()
at flash.display::Sprite$iinit()
at flash.display::MovieClip$iinit()
To avoid this error simply declare my_mc as public:
public var my_mc:MovieClip;



13 Comments:
much help thanks! :)
thanx andrew, you saved me some time.
but i'm still a bit confused.
if i declare my_mc private in the base class A it should be perfectly reachable to class primeA because it inherited it. why can't primeA then control that private instance?
thanx
Inheriting classes cannot access a private property in AS3.
They could do so in AS2, because only "public" & "private" were supported. But AS3 now supports "protected"
public = unrestricted access
private = class only access
protected = class & extending class access
Thanks Andrew,
It was really a relief.
I was going crazy after this.
Thanks once again!
Thanks Andrew, this is driving me crazy!.
It is a pain to have to declare the properties manually though, any ideas of how could this be done parametrically?
If your "Automatically declare stage instances" option is off, you can also get code 1056 errors by referring to manually created instances that have not been declared at all let alone as private instances. For example:
this.aProperlyDeclaredChildMovieClip['anUndeclaredGrandChildMovieClip'].someMethod();
*BOOM* says the compiler. Well, "Error #1056" says the compiler, anyway.
it also happens if you have turned off the "visibility" of the layer in the Flash CS4 IDE. The layer and it's contents are not compiled, and this same error is displayed.
Just a note -- this occurred for me when declaring the instance protected, as well.
hi all-
my problem acts like this, but doesnt seem to be the same problem:
I have a swf that works great when loaded directly, but throws error#1056 when loaded into another swf...
thoughts? dying on the vine, here
how could this be done parametrically?
Great riff, Paiaso loco.
Thanks, Andrew for this. I came across this problem as another who'd never seen it before and was prepared to spin my wheels over it for awhile. I found this post in a search pretty quickly and it saved the day.
I never even know the toggle was there. I'm going to use it 100% of the time from now on, because then I can get code hinting and such when writing to objects that are .fla instantiated.
Hi:
Thanks for this post, it was really helpful.
I tried declaring the vars as protected (to avoid possible interferences) but it gives the same error as when declared private.
Hey Andrew,
I have made a class A that is attached to a movie clip that contains another movie clip which has attached the class B.
I am getting the #1056 error fired from the class B because it can't find the property in class A. The reason is that somehow class B is compiled before class A, which is weird because class B belongs to a movie clip that resides into a movie clip of type A.
Is there any way that I can control the class compile order, or any reasonable solution to this problem?
Cheers,
Alex
THANKS!!
One horrible gotcha to this is that if you want to declare stage instance names for multiple similar clips, you then have to define variables for each of them.
This is troubling if you are doing rudimentary data association using ID's, which is a not-so-rare technique... (e.g; associating slides with a product ID or something)
Thanks Andrew
Thanks Andrew! I had no idea what I was doing wrong...
Thanks so much...that saved me a lot of headaches...
when you save a flash 8 file into cs3 or higher the declare stage instances setting in as3 settings is automatically unchecked.
its nice that your post popped on google on just the search of the error.
/no1
reminded me i had to manually update the as3 settings.
Post a Comment
Links to this post:
Create a Link
<< Home