Automatically Declare Stage Instances
I was doing some work today in Eclipse/FDT 3 and I kept running into something that I wasn't expecting. In FDT 1.5 I would normally create a movie clip symbol in the Flash IDE and maybe have more clips inside of it, like say a bg_mc and a title_txt. Then, in FDT, I would define the variable at the top of my class so that I could use it in the code later on:
-
public var bg_mc:MovieClip;
Now, coming over to AS3 and FDT 3, I expected the same behavior. I went about my business in defining my variable at the top of my class and then using it later on in the class somewhere. I went back to Flash to compile the project and got the following in the output panel:
1151: A conflict exists with definition bg_mc in namespace internal.
After some quick fiddling around and Google searching I realized the problem. If you don't want FDT 3 to give you errors and want to be able to declare your instances in the class itself, go into File > Publish Settings > Flash > Settings and uncheck "Automatically declare stage instances". This will prevent the Flash IDE from throwing the error in the output panel and will make Eclipse/FDT happy because you aren't trying to use an instance that you never defined. YAY!
If you found this post useful, please consider leaving a comment, subscribing to the feed, or making a small donation.
3 Comments
well, i normally define my "instances" in my classes as public so I can access them elsewhere, but you certainly don't have to and its for your discretion.
Please declare as PUBLIC, otherwise there will be an error:
ReferenceError: Error #1056: Cannot create property xxx on uk.co.xxx.xxx.xxx.
at flash.display::Sprite/flash.display:Sprite::constructChildren()
at flash.display::Sprite$iinit()
at uk.co.xxx.xxx::CardGame$iinit()











Useful little tid-bit, although I don't understand why we need to define the MovieClip as public?