« Twitter Me? | Main | Order Adobe CS3 and Benefit GalaxyGoo »

Can't have manually set instance names, with Flash9 AS3 Preview?

So, I'm playing around with the Flash9 AS3 Preview, and updating a project I'd built in Flash8 to AS3....when I get stuck. I can't figure out how to fix an error message I get when trying to run a Document Class...so I go back to the tutorials, and start from scratch. I tinker with the files I create with the tutorials. It all goes well.

But when I go back to my old file, I still can't get my document class to run without a fatal error. So....I go through all the visual assets in the fla. Eventually, I find one movieclip on the stage with an instance name. When I remove this instance name, my document class works like a charm.

So, why does having a manually set instance name cause an error? I'd very much like this explained, because I think I'm missing something important. Does it have something to do with not setting insance names in AS3?

Comments

Hi Kristin. I had the same problem this week at my new job and my colleague helped me out. I've been using Flex since it came out of beta, but first used the Flash 9 alpha this week and was trying to use instance names on some MCs. What you have to do is have all your instance names as public variables in your document class. Make sure they are public vars (I was trying to use private and it wouldn't compile.)

you gotta declare the variable and import the movieclip classes

Pretty hard to comment without actually seeing the error but i'd put it down to one of 2 things.

1. You haven't declared the var in your class therefore the compiler isn't able to create it.

2. You have declared the var as private, and therefore the compiler can't access the var.

Try declaring the instance in you class as public, or wait till Tues :).

When you set an instance name on the timeline, it becomes a class variable of your document class, and you don't need to declare it. If you are declaring instance name of your movieclip as a variable in your class, as it is usually done in AS2, you will get an error.

For me, this is bad because I'd like to have every visual asset on stage accounted for in the class. What I usually do is assign the instance name on the movieclip on stage to a variable class:

var myMovie:MovieClip = myInstance_mc;

where "myInstance_mc" is the instance name of the moviclip on stage. Then, I just refer to it through "myMovie"

Hope that helps.

If you bind a clip to a class in AS3, any of its stage contents with instance names essentially try and auto-declare themselves in your class. If there is no declaration in the class, then you will get an error, since the class is not dynamic, and the property does not exist.

If your document class is dynamic it will allow the behaviour.

Keep in mind that you are talking about alpha software, and the final version of Flash 9 will possibly have a different behaviour.

Hope this helps...

The movieclip is not refered to, at any time, by the document class, but the compiler is looking for a class to bind to that clip,and stalls on an error (saying it's looking for that class).

I can see this becoming a real pain, whenever updating old projects. You'll have to make sure there aren't *any* instance names declared inside the fla.