views:

406

answers:

1

This happens to me a lot and I've yet to find a good solution. Say you have two classes, Tree (com.company.Tree) and Fruit (com.company.Fruit). On the stage in Flash, the Tree has an instance of Fruit (class=fruit1, base class=com.company.Fruit), and it's instance name is fruit. Everything is fine, until you duplicate the tree and fruit movie clips to create a 2nd tree, which has a DIFFERENT instance of Fruit (class=fruit2, base class=com.company.Fruit), but whose instance name in the 2nd tree is also fruit. This is necessary because the code for the Tree class references "fruit" (fruit.x += 20, for example).

I get this:

 Warning: All instances named 'fruit' will be automatically declared as fruit1 in symbols that use fruit as their base class. In symbols that are linked to user-defined base classes, instances with the same name must be of the same type.

And of course this:

TypeError: Error #1034: Type Coercion failed: cannot convert fruit2@4be85871 to fruit1.
A: 

Are you using the compile option to "Automatically declare stage instances"? In this case, you may have to disable that and add:

public var fruit:Fruit;

to your Tree class. This would assign "fruit" to your MovieClip on the stage with an instance name of "fruit" and avoid the conflict. Check this post out for more.

Typeoneerror