6 Replies Latest reply on Jun 29, 2007 12:11 PM by WebmastaDj

    Functions in a class

      Ok, I have found defining classes in .as files can be very useful for me. I have a few functions that are being called over and over again in different movies. There is what I want / need to do in order to stream line the creating and updating of the flash site. I want to see if I can put those same functions into a class (.as file) so I can access them from anywhere in the flash movie. The problem is when I just try to copy and paste the functions to the .as file (func.as) and then call the function by, func.FunctionName I get errors. The movie is calling the functions when buttons are pressed. Any ideas? I will attach some functions I am using that I would like to move to the func.as file.
        • 1. Functions in a class
          WebmastaDj Level 1
          I have tried this. But get an error of

          1119: Access of possibly undefined property BackToMenu through a reference with static type Class.
          • 2. Re: Functions in a class
            SymTsb Level 2
            OK........ Couple of things I see....


            public class func{ // This is the name of your class and as such, it needs a constructor.....

            public function func() {
            // Doesn't need to do anything

            Your import should be inside your package but outside the class definition

            You need to import your package into your Flash shell before you can call the BackToMenu funciton (this is the real reason for the error).

            If you get an error about not being able to nest packages, you'll need to adjust things

            package com.mysite.common {
            the above line will assume that you have folders relative to your flash shell of the same names.....

            com \ mysite \ common \ func.as

            If this doesn't make sense, just let me know. We'll get it straightened out.
            • 3. Functions in a class
              WebmastaDj Level 1
              change what you said...Still getting the same problem (error).
              The New Code is attached.
              • 4. Re: Functions in a class
                SymTsb Level 2
                No no....

                • 5. Functions in a class
                  WebmastaDj Level 1
                  Do I need the "com.mysite.common" and will that mess up the file name? Doesn't the file name have to be that?

                  I already have one .as file that is loading global varibles. I would like to combine these to files into one once I get the functions working. Attached is the code for the other .as file (glo.as). I don't have to have a "package name" on that file. I just call the variables with: glo.ConnectionSpeed and it works perfectly.
                  • 6. Functions in a class
                    WebmastaDj Level 1
                    Ok, I have updated the .as file and the .fla file. Now I am recieving the following Output error (it compiles fine).

                    TypeError: Error #1034: Type Coercion failed: cannot convert func@5117efe1 to flash.display.MovieClip.
                    at func/BackToMenu()