Search code examples
flashactionscript-3linkage

Symbol Linkage in ActionScript 3 / Flash CS5


I'm new to Flash/ActionScript and have run into a bit of trouble creating a custom base class for some of my symbols.

I have a flash file with a number of planets in it, and I want to store some information about each planet, so I've created a Planet class in an actionScript file, with things such as minimum and maximum temperature for each planet.

In my main flash file I have a symbol made for each planet with a custom picture and each planet has different animations. What I want to do is set the class of each of these symbols to planet, I originally did this by just changing the linkage in the Library to be Planet, but that only worked for one symbol, once I changed it on another it stopped working, it won't let you set them to the same class. So I tried right clicking on it and going to properties and setting 'export for actionscript' then I name the class 'Mercury' or 'Venus' and setting the base class to Planet (planet extends movieclip). It assures me that even thought it can't find Venus it will generate it for me at export time. I press command + enter and it comes up with these compile time errors:

../Main.as, Line 9  1046: Type was not found or was not a compile-time constant: Venus.

and

..Main.as, Line 31  1046: Type was not found or was not a compile-time constant: Mercury.

When it was working with just 1 class, it would create an instance of Planet with a default constructor, and then in the Main method I'd call an 'initialize' function on that class which would let me set the instance variables and event handlers for use later on. I just need to know how to make flash call create more instances of Planet for my other symbols, without combining them into the one thing.

Any tips would be appreciated! Thanks.


Solution

  • Your question was a little confusing; however it seems that you want to create a base class "Planet" and have other classes such as Mercury and Venus inherit properties from it. From here you could set up your library symbols to use Plant as the base class. Here's how you could go about doing this:

    Base class:

    package
    {
        import flash.display.MovieClip;
    
        public class Planet extends MovieClip
        {
            // vars
            public var temperature:Number;
            public var radius:Number;
        }
    }
    

    Classes for your actual planets (need one for each planet):

    package
    {
        public class Venus extends Planet
        {
            /**
             * Constructor
             */
            public function Venus()
            {
                // set properties here
                temperature = 900;
                radius = 12.93;
            }
        }
    }
    

    If you create these files, then all should work fine.