7 Replies Latest reply on Jan 31, 2007 12:39 AM by Peter Lorent

    AS 2.0 and class question

    Level 7
      I put the following, which is for my buttons into an .as document:

      this.nav.contact_btn.onRelease = function():Void {
      trace("test");
      };


      When I compile my .fla, it get the following error:

      **Error** /Users/brian/Documents/Capitola
      Media/Development/Flash/nav.as: Line 3: ActionScript 2.0 class scripts
      may only define class or interface constructs.
      };


      And I guess I don't really get it. Can someone explain this to me, that
      would be great!!!

      Thank you!
        • 1. Re: AS 2.0 and class question
          Hi,

          my first question is how did you link your nav button to the ".as" file? ... It seem like you link it through the library and if so, your code is not a declaration of a class. Every class need to be declare as a class or it will only be some actionScript code in a ".as:" file.

          You should try something like this (if you linked the class trough the library):

          • 2. Re: AS 2.0 and class question
            Level 1
            Me Again,

            you may also want to not link your nav button to the class. You can just instanciate the class and pass as a parameter the nav button (composition). So on your timeline you instanciate it :

            var nav:Navigation = new Navigation(_root.nav.contact_btn);
            // note that this way your Navigation Class need to be in the same folder than your fla file
            // if you want to have your class in a sub-folder use this (assuming that the sub-folder is called "classes"

            import classes.Navigation;

            var nav:Navigation = new Navigation(_root.nav.contact_btn);

            So now the class will go like this:

            • 3. Re: AS 2.0 and class question
              Peter Lorent Level 2
              Show the complete code Brian.
              • 4. Re: AS 2.0 and class question
                Level 7
                OK,
                I think this might be getting more complicated than I wanted to make it.
                I just wanted to have the code for my button in an external as
                document. Does that mean I have to make it a class? Right now I have two
                external as documents.

                My main fla has the following AS in it:

                stop();
                #include "capitola.as"
                #include "nav.as"



                capitola.as looks like this and just is the opening sequence so far. So
                this is not a class, just external .as document.
                import com.mosesSupposes.fuse.*

                ZigoEngine.register(Fuse,PennerEasing,FuseFMP);

                //Initial Opening Sequence of the site
                //*************************//
                function initialOpenSequence():Void{
                trace("openSequence has started");

                this.attachMovie("site_frame", "site_frame",
                this.getNextHighestDepth(), {_x:0, _y:0, _alpha:0});
                this.attachMovie("logo", "logo", this.getNextHighestDepth(), {_x:100,
                _y:26, _alpha:0});
                this.attachMovie("mainImg", "mainImg", this.getNextHighestDepth(),
                {_x:80, _y:90, _alpha:0});
                this.attachMovie("line", "line01", this.getNextHighestDepth(), {_x:80,
                _y:85, _alpha:0});
                this.attachMovie("line", "line02", this.getNextHighestDepth(), {_x:80,
                _y:280, _alpha:0});
                this.attachMovie("nav", "nav", this.getNextHighestDepth(), {_x:80,
                _y:290, _alpha:0});
                this.attachMovie("indexText", "indexText", this.getNextHighestDepth(),
                {_x:110, _y:375, _alpha:0});


                var fOpenSite:Fuse = new Fuse();
                fOpenSite.label = "openSequence"; // label is a convenience for
                traceItems() calls.
                fOpenSite.autoClear = true; // set instance to self-destroy after
                completion

                fOpenSite.push(
                [
                {target:site_frame, _alpha:100, seconds:3, ease:"easeOutQuad"},
                {delay:1, target:logo, _alpha:100, seconds:1, ease:"easeOutQuad"}
                ]
                );
                fOpenSite.push({target:mainImg, _alpha:100, seconds:2,
                ease:"easeOutExpo"});
                fOpenSite.push({target:line01, _alpha:100, seconds:2, ease:"easeOutExpo"});
                fOpenSite.push({target:line02, _alpha:100, seconds:2, ease:"easeOutExpo"});
                fOpenSite.push({target:nav, _alpha:100, seconds:2, ease:"easeOutExpo"});
                fOpenSite.push({target:indexText, _alpha:100, seconds:2,
                ease:"easeOutExpo"});

                fOpenSite.start();

                }
                initialOpenSequence();


                function afterFuse():Void{
                trace("fuse comlete");
                }



                Then I have the code for the navigation in nav.as and that is it so far.
                this.nav.contact_btn.onRelease = function():Void {
                trace("test");
                };
                this.nav.contact_btn.onRollOver = function():Void {
                trace("test");
                };
                this.nav.contact_btn.onRollOut = function():Void {
                trace("test");
                };




                That is all I have. I was just wondering why I am getting that error
                message from the nav.as document?

                Thanks for any help!
                Brian


                • 5. Re: AS 2.0 and class question
                  Peter Lorent Level 2
                  >>Does that mean I have to make it a class?

                  No, normally you don't.

                  As strange as it might seem, the error occurs in capitola.as and specifically the lines:
                  15. this.attachMovie("nav", "nav", this.getNextHighestDepth(), {_x:80, _y:290, _alpha:0});
                  27. fOpenSite.push({target:nav, _alpha:100, seconds:2, ease:"easeOutExpo"});

                  If you comment those lines, the script validates.

                  You cannot use the word 'nav' for the linkage identifier of your movieclip and name your as file nav.as
                  Rename nav.as to navigation.as and delete nav.as
                  Then you should be in the clear.
                  • 6. Re: AS 2.0 and class question
                    Level 7
                    LuigiL,
                    thank you so much!
                    I was actually really wondering about it, because I commented out the
                    include for nav.as and was still getting the error.

                    Thanks,
                    Brian
                    • 7. Re: AS 2.0 and class question
                      Peter Lorent Level 2
                      You're welcome.