6 Replies Latest reply on Aug 28, 2007 1:23 PM by Newsgroup_User

    Action Script Linked to Button...

    shojinate
      Hi, here is what I am working with:

      The main scene, with two labels 'Intro' and 'About'. Initially the playhead stops at the first label 'Intro'. I have a movie clip with an instance name navLinks1-1 on the stage. Within that movie clip is another with an instance name of navLinks1. Within that are several buttons including one with an instance name of btnAbout.

      Now back on my main scene I've entered this code:

      navLinks1-1.navLinks1.btnAbout.onRelease = function(){
      gotoAndStop("About");
      }

      Obviously I'd like to click the About button and tell the playhead to go to the About section, but it isn't doing it. Instead I get an error message saying:

      **Error** Scene=Scene 1, layer=Nav, frame=1:Line 1: Syntax error.
      navLinks1-1.navLinks1.btnAbout.onRelease = function(){

      Total ActionScript Errors: 1 Reported Errors: 1

      Can anyone help me out? Thanks so much!!
        • 1. Re: Action Script Linked to Button...
          Damon Edwards Level 3
          get the -(dash) out of the instance name
          • 2. Re: Action Script Linked to Button...
            Level 7

            "dzedward" <dzedward@gmail.com> wrote in message
            news:fb1l0g$cum$1@forums.macromedia.com...
            > get the -(dash) out of the instance name

            Yup, that's the problem. Removing it in the code also means, of course,
            you'll have to change the actual instance name reflected for that objectin
            the Property inspector. (You could replace the "-" with an underscore, "_",
            if you like. It's just that the only legal characters for variables and
            instance names are alphanumerics (a-z, 0-9) -- as long as you don't start
            the name with a number -- and the punctation marks _ [underscore] and $
            [dollar sign].)


            David Stiller
            Co-author, Foundation Flash CS3 for Designers
            http://tinyurl.com/2k29mj
            "Luck is the residue of good design."


            • 3. Re: Action Script Linked to Button...
              shojinate Level 1
              Thank you! I am not getting the error message so the syntax must be correct. It's still not doing anything though, why would that be?

              Maybe it has something to do with the movie clips? In 'navLinks1_1 the timeline plays a bunch of empty frames until it hits frame 75 which introduces the next movie clip 'navLinks1' along with an action to stop there. 'navLinks1' has three buttons that fade in one after another.

              So in the main movie you have to wait a little bit while the elements fade in. Then I'd like to be able to use them (of course).

              Thanks again!!
              • 4. Re: Action Script Linked to Button...
                Level 7
                shojinate,

                > Maybe it has something to do with the movie clips?
                > In 'navLinks1_1 the timeline plays a bunch of empty
                > frames until it hits frame 75 which introduces the next
                > movie clip 'navLinks1' along with an action to stop there.

                That would be your problem. In this line ...

                navLinks1_1.navLinks1.btnAbout.onRelease = function(){
                gotoAndStop("About");
                }

                ... you're referencing the following object:
                navLinks1_1.navLinks1.btnAbout. If that object doesn't exist yet (because
                the timeline hasn't progressed that far), then you can't reference the
                object, and no event handler has been assigned.

                Make sure that navLinks1 and btnAbout are present from the get go (from
                frame 1) and, if necessary, move them off the Stage visually or set their
                _alpha properties to 0, then bring them back at the desired keyframe of
                navLinks1_1. Their instance names will have to be available the whole time.


                David Stiller
                Co-author, Foundation Flash CS3 for Designers
                http://tinyurl.com/2k29mj
                "Luck is the residue of good design."


                • 5. Re: Action Script Linked to Button...
                  shojinate Level 1
                  Thanks, I got it. I guess I'll need to keep what I wish to affect on the first frame of the timeline. Just out of curiosity, is there a way to write the script so that I could make my previous scenerio work?
                  • 6. Re: Action Script Linked to Button...
                    Level 7
                    shojinate,

                    > Just out of curiosity, is there a way to write the
                    > script so that I could make my previous scenerio
                    > work?

                    You could assign the event handler in the timeline of the movie clip
                    that contains the button, but it's generally a good idea to keep your code
                    in a single timeline, so it's easier to find.


                    David Stiller
                    Co-author, Foundation Flash CS3 for Designers
                    http://tinyurl.com/2k29mj
                    "Luck is the residue of good design."