20 Replies Latest reply on Nov 24, 2007 11:37 AM by joeflashTO

    Button link to a specific frame in time line

    TnaE Level 1
      Ok I have created my buttons and the content for the specific frames. I have named the button and given it an instance name. I have also given my specific frame a name and set that label type to Name.

      Whats the code for turning getting my button to link to a specific frame?

      I've also done the stop() code in each frame as I want it to stop at each frame until the button is clicked again.

      I have more than one button and each will link to a different frame.

      Thanks.
        • 1. Re: Button link to a specific frame in time line
          DanelKirch Level 1

          gotoAndStop(frameLabel);
          • 2. Button link to a specific frame in time line
            TnaE Level 1
            Thanks! Where should I put that? Do I need an event listener or anything like that with my buttons name it? Sorry I know, I'm a total flash noob.

            I'm using flash CS3 by the way.

            When trying to do it this way:

            stop();
            home_bttn.onRelease = function () {
            gotoAndStop(home);
            }



            I get this annoying crap:

            1119: Access of possibly undefined property onRelease through a reference with static type flash.display:SimpleButton.
            1120: Access of undefined property home.


            I've checked it time and time again and my button instance name and my frame name are correct. I dunno what the crap is causing the problem.
            • 3. Re: Button link to a specific frame in time line
              joeflashTO Level 1
              What you just showed us is AS2 code. Your error shows that you have your SWF set for AS3, which uses events differently. Set your Publish Settings to AS2, and the code should work. Or upgrade the code to AS3.
              • 4. Re: Button link to a specific frame in time line
                TnaE Level 1
                Thanks joe. I tried converting my project to AS2 but it just caused more problems with some of my other action script. Do you happen to know where I could get that code in AS3? I've spent a good 2 hours or more searching on google for the AS3 code to do this and I can't come up with anything usable. :-(
                • 6. Button link to a specific frame in time line
                  TnaE Level 1
                  Thanks Joe you the man. I'm having one problem with this script though and its that I'm getting a duplicate function error when trying to use it for more than one button to frame link. How can I use it multiple times?

                  Nevermind I forgot you had to add a number to the function name like I did below:

                  import flash.events.*;

                  home_bttn.addEventListener(MouseEvent.MOUSE_UP,releaseHandler);
                  function releaseHandler(evtObj:MouseEvent):void
                  {
                  this.gotoAndStop("home");
                  }

                  about_bttn.addEventListener(MouseEvent.MOUSE_UP,releaseHandler2);
                  function releaseHandler2(evtObj:MouseEvent):void
                  {
                  this.gotoAndStop("about");
                  • 7. Button link to a specific frame in time line
                    TnaE Level 1
                    Ok I'm having a new problem with this actionscript. I have the links working but when I click one and go to the new frame my scrollable text box doesn't work. The scrollbar will move but the text doesn't.
                    • 8. Re: Button link to a specific frame in time line
                      joeflashTO Level 1
                      Hard to tell why your app is not working unless I can see what you're seeing. Post your code using Reply > Attach Code and we'll see what we can do.
                      • 9. Button link to a specific frame in time line
                        TnaE Level 1
                        Sorry. :-)

                        I've got a typical flash website with each page having a scrollable text box. Theres a button that links to each frame that contains a text box. I've put the code in that I'm using to link the buttons to a specific frame.

                        And i just noticed something. When I first publish a flash preview of my website the text box can be scrolled. If I click a link and go to another page the box on that page won't work. If I click the link to go back to the original page that worked after first publishing the text box doesn't work on that original page anymore.

                        I don't know if that helps but it might give you some kind of idea of whats going on.

                        The only other action code I have in the project is stop() is in the first frame of the movie in the same frame set as my first page.
                        • 10. Re: Button link to a specific frame in time line
                          joeflashTO Level 1
                          Your code looks okay. But I get the feeling there's something I'm not seeing here in your code. It could be that there is code on your first frame that you use to initialize the TextArea in the first frame, but you also have TextAreas in subsequent keyframes. Even if you give the TextAreas in those subsequent frames the same instance names, if you are placing splitting up the layer/timeline with keyframes each having a TextArea, they are not the same instance, and so the code you used to initialize your component on the first frame is not initializing TextAreas on subsequent frames.

                          Under the hood, AS 3 compiles each frame on the timeline into a separate class, with code on that frame being members of that class, and the assets on the authoring stage at that frame become objects instantiated as child objects of that "frame object". So code which initializes an object on one frame will not initialize an object on another keyframe.

                          If that is what's causing the problem, your solution is either to
                          1. duplicate the initialization code on each keyframe where you have TextArea components, or
                          2. have the keyframe at the frame layer with the initialization code span multiple frames, acros multiple labelled sections of the timeline.
                          • 11. Re: Button link to a specific frame in time line
                            TnaE Level 1
                            Joe the only other code I have in the entire document, at least that I've done myself is stop() in the first frame of the first text area. Could that be doing something?
                            • 12. Re: Button link to a specific frame in time line
                              joeflashTO Level 1
                              Tell you what. Give me a dump of all the code in your FLA, and we'll see if we can figure this one out.
                              1. In Flash, Select Window > Movie Explorer;
                              2. In the Movie Explorer panel, besides 'Show:' click the right-most
                                button, 'Customize what items to show';
                              3. Select Show: 'ActionScript', 'Layers', 'Frames', Context: 'Movie
                                Elements', 'Symbol Definitions'

                              4. Go to Movie Explorer panel Properties > Copy All Text To Clipboard;
                              5. Paste the code into the Attach Code portion of your reply.
                              • 13. Re: Button link to a specific frame in time line
                                TnaE Level 1
                                Would it be easier for you if I just gave you a copy of the flash file itself to look at?
                                • 14. Re: Button link to a specific frame in time line
                                  joeflashTO Level 1
                                  If you hire me, I'll be happy to look at any files you want ;)

                                  Seriously, posting the code in this fashion will give us an idea of the internal structure of your will FLA, plus the code, and enable others to benefit from this thread as well.
                                  • 15. Button link to a specific frame in time line
                                    TnaE Level 1
                                    Ah ok gotcha. :-) I'll see if I can get it to post.


                                    EDIT: Hmmm I can't find the Movie Explorer Panel for this step:

                                    # Go to Movie Explorer panel Properties > Copy All Text To Clipboard;
                                    • 16. Re: Button link to a specific frame in time line
                                      joeflashTO Level 1
                                      Movie Explorer panel Properties = drop down menu just below the top right close button.
                                      • 17. Button link to a specific frame in time line
                                        TnaE Level 1
                                        Ok maybe I got it, Is this what you need?
                                        • 18. Re: Button link to a specific frame in time line
                                          joeflashTO Level 1
                                          I've duplicated an FLA with exactly the assets you have in the same places, with the code on the main timeline. And mine didn't work, just the same problem as you had. The solution I proposed above works, but it is not the only way (See #2 below).

                                          On Frame 1, select the UIScrollbar. if you look in the Parameters tab of your UIScrollbar component, you'll notice that the scrolltargetName refers to Instance_0. This is a default instance name assigned by the Flash compiler, because you did not give your dynamic textfield an instance, and your UIscollbar is referencing that. Now go to Frame 4. You will find that your dynamic textfield has the same instance name, and the UIScrollbar is referencing the same instance. Problem is, you have more than one textfield on more than one frame using and referencing the same instance name, your UIScrollbars will get confused as to which textfield is actually "Instance_0". The moment you click to another frame, you've confused the UIScrollbar(s), so they never work again.

                                          The solution is simple.

                                          First, put a stop() action on the first frame, if you have not already done so, so your timeline stays put until you click on a button.

                                          Then you can solve the problem in one of two ways:
                                          1. Give your textfields different instance names, and make sure the scrolltargetName property of each UIScrollbar refers to its respective textfield.
                                          2. Or set the text dynamically, which after all is what a dynamic textfield is for. Have only one textfield/UIscrollbar combo, on the first frame, and place code on a keyframe for each section which changes the text or htmlText property of the textfield.

                                          That should work. It did on mine.
                                          • 19. Re: Button link to a specific frame in time line
                                            TnaE Level 1
                                            Damn Joe I bow at your feet as the jam between your toes has more flash skillz than I do. Thanks a ton man. If you have a prefered link to a website of yours or something I'll gladly put a link to it on my website when its done. Thanks again man.
                                            • 20. Re: Button link to a specific frame in time line
                                              joeflashTO Level 1
                                              Jam between my toes, LOL that's a good one. And you're welcome.