Pergunta

You may observe from the title that I'm new to programming and Actionscript 3. I don't think I understand how classes work. Especially in AS3. I thought they were a bunch of behaviour that you can attach to your objects and all objects with same class will show same behaviours and will have their own specific values.

I learnt about base classes now and I'm a little bit confused about these two types of classes.

I have two objects on the scene which are 'apple' and 'pear'. They are both 'item's. I want to give them variables such as 'name' and 'icon'. Since it will be an inventory system later, I want to use a class that will apply these variables to each object that I assign 'item' class. I did it with 'apple' object. It's base class is 'flash.display.movieClip' and class is 'item'. I set it's name and icon values on my timeline. Things were working fine.

I added 'pear' object then and I discovered that I cannot assign 'item' class to multiple objects. I researched a little and found out that I should give 'item' as a base class instead of class. Ok, I changed their base classes to 'item'. But what will be classes of these objects? I really don't understand and would appreciate if someone explains me in a simple way.

Foi útil?

Solução

What you will need to do is set the Base Class on both apple and pear to your item class. Then, you will set the Class to Apple for apple, and Pear for pear.

Depending on your settings, you may get a warning telling you that

A definition for this class could not be found in the classpath, so one will be automatically generated in the SWF file upon export.

This is not an error, and you may dismiss it.

You will also want to make sure that your item Base Class extends from either the MovieClip or Sprite class.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top