13 Replies Latest reply on Jun 8, 2007 7:01 PM by Special-k

    1045 Interface Questions AS3

    Special-k
      Hello,

      I've recently decided to take a look at AS3, and I was in the process of seeing what kind of changes I needed to do with my code to make it AS3 compliant. I did the changes to import the flash.display.MovieClip class. As I was going through this circular pattern (compile, flash tells me what's wrong, I correct it...) this one area has stumped me.

      I get the following error: "1045: Interface newI was not found."

      What am I doing wrong? Are Interfaces allowed with AS3 code?

      Thanks,

      Kelly


        • 1. Re: 1045 Interface Questions AS3
          hciguy
          While I do not know the problem, it appears AS 3.0 does still have interface keyword:

          "interface definition keyword
          Usage


          interface InterfaceName [extends InterfaceName ] {}

          Language Version : ActionScript 3.0
          Player Version : Flash Player 9

          Defines an interface. Interfaces are data types that define a set of methods; the methods must be defined by any class that implements the interface.

          An interface is similar to a class, with the following important differences:

          * Interfaces contain only declarations of methods, not their implementation. That is, every class that implements an interface must provide an implementation for each method declared in the interface.
          * Interface method definitions cannot have any attribute such as public or private, but implemented methods must be marked as public in the definition of the class that implements the interface.
          * Multiple interfaces can be inherited by an interface by means of the extends statement, or by a class through the implements statement.

          Unlike ActionScript 2.0, ActionScript 3.0 allows the use of getter and setter methods in interface definitions.

          Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash tab of your FLA file's Publish Settings dialog box. This keyword is supported only when used in external script files, not in scripts written in the Actions panel.

          See also
          class
          implements
          Interfaces"

          From http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/ under Statements, Keywords, etc.

          • 2. 1045 Interface Questions AS3
            Special-k Level 1
            Yeah, that's what's so confusing. I've seen the references in the docs (and even how it allows getter/setter functions now), but no matter what, each interface I try(event the example above) becomes not found.

            It (Flash) walked me through the error of the interface file when I originally created and implemented it (was originally "public function announceEvent( t:Number):void;"
            ), but after I corrected that error, I received error 1045. How can it see it at one point and not see it at another?

            Does anyone else have this problem by chance?

            Cheers,

            Kelly

            *edit (a couple of quick grammatical errors)
            • 3. Re: 1045 Interface Questions AS3
              hciguy Level 1
              Do you have to import the interface file or anything? Sounds like a problem locating it.
              • 4. Re: 1045 Interface Questions AS3
                Special-k Level 1
                yeah, I've tried that too (see code for the variation). It still tells me that the same line (class something extends MovieClip implements newI{) still can't find the interface.


                Thanks.

                Kelly

                • 5. Re: 1045 Interface Questions AS3
                  hciguy Level 1
                  I know this sounds dumb but you have your class path set right, right? So that your interface is in the class path...and whtn you import it, you're importing it in that path?

                  Just making sure...hmmm
                  • 6. Re: 1045 Interface Questions AS3
                    Special-k Level 1
                    yeah, initially I thought that too, but it finds the class because it asks about the interface file (and they're both in the same folder as the fla).

                    I mean if you do the same (create the class and interface files and then set it up in flash). Would you get the same issue as me?

                    Thanks again

                    • 7. Re: 1045 Interface Questions AS3
                      hciguy Level 1
                      Try putting it in a package and declaring it public. When I tried it that removed the error:

                      package here.there.interfaces {
                      public interface newI{
                      function announceEvent( t:Number):void;
                      }
                      }

                      Work?
                      • 8. Re: 1045 Interface Questions AS3
                        hciguy Level 1
                        It works for me.

                        • 9. Re: 1045 Interface Questions AS3
                          Special-k Level 1
                          Ahhh ha! Man I hate the little things! hciguy, thanks for all your help. I changed the interface to include package wrapper, but I also found out it was because I didn't declare something to be public (the class decloration)

                          Thanks again,

                          Kelly
                          • 10. Re: 1045 Interface Questions AS3
                            hciguy Level 1
                            As a return favor, do you think you could explain to me exactly what interfaces are used for? I basically understand the package/class hierarchy but not sure why you'd use an interface. Looks like it just holds empty methods but then you have to make the methods work in the class that implements the interface?

                            Thanks man. Glad it worked.
                            • 11. 1045 Interface Questions AS3
                              Special-k Level 1
                              hciguy, sure thing. I was a little confused when I first learned of them too.

                              Currently when you write classes they are structured, but only in terms of knowing you write getter/setters functions, functions and variables. Oh and let not forget my issue (defining if an item is private or public). After that there isn't really much structure to your class. You can freely write functions/methods all day long.

                              The joy of Interface files are to provide structure to your class. When doing an interface class you define what function/methods a class needs to implement, but not actually writing out the methods in detail. It guarantees that this class is required to contain the functions or methods of the Interface file. Something like this would be great if you wanted your classes to have a series of seach methods. So that you keep consistancy you create an interface. The interface holds the function names. Then you just implement the interface to the class and fully create the methods.

                              At first you'll see it as repetitive or boring, but later on you'll see how it helps to save your but when you have lots of classes using those methods (at least that's how it was with me).

                              Hopefully that makes some sense and thanks again,

                              Kelly

                              P.S. Of course you can see me using the interface in the class something above.
                              • 12. Re: 1045 Interface Questions AS3
                                hciguy Level 1
                                So basically they just ensure that the necessary methods are there? Are you saying if a class implements an interface, and that class doesn't implement all the methods, it won't work? Is that why it is helpful?

                                Do they also go to help ensure consistency so that, say, when a search is done - and you implement the search interface - then you have to be sure you implement all the right methods?

                                Basically interfaces exist solely for the sake of structure. They don't have code or any functionality, right?

                                Thanks!
                                • 13. Re: 1045 Interface Questions AS3
                                  Special-k Level 1
                                  Sounds like you've got it.

                                  The class will fail to compile if you you don't create the method(s) based upon the interface you are implementing. And because of this, the class will fail. So to recap interfaces help to privide structure, consistancy and/or order to your classes. It makes it easier to allow for commonality between multiple classes utilizing the same methods/functions.

                                  You're more than welcome, and thank you too,

                                  Kelly