14 Replies Latest reply on Sep 29, 2009 9:51 AM by kglad

    Action Script Buttons Heirarchy Help

    onlinegenie

       

      This is my first post and im hoping someone out there will be able to help I am a developer in JS and ASP but never learnt actionscript and am completely stuck.

       

      Basically I am using the sliding code from a tutorial i found online, what i want to do is have buttons inside the Content 1, content 2 etc which are basically the pages which are then put into a holder then added to the main scene called CONTENT.SWF, I also have an index.swf which uses a swf loader to bring the CONTENT.swf in, confused yet i am......

       

      The buttons work if i add them to the main scene in Content.swf but not in each of the content1, content2 etc. So i am sure its to do with hierarchy of buttons layers going down or something.

       

      var currentPosition:Number = contentHold.content1._x;

      var startFlag:Boolean = false;

      menuSlide = function (input:MovieClip) {

                      if (startFlag == false) {

                                     

                                      startFlag = true;

                                     

                                      var finalDestination:Number = input._x;

                                      var distanceMoved:Number = 0;

                                      var distanceToMove:Number = Math.abs(finalDestination-currentPosition);

                                      var finalSpeed:Number = .3;

                                      var currentSpeed:Number = 0;

                                      var dir:Number = 1;

                                     

                                      if (currentPosition<=finalDestination) {

                                                      dir = -1;

                                      } else if (currentPosition>finalDestination) {

                                                      dir = 1;

                                      }

                                     

                                      this.onEnterFrame = function() {

                                                      currentSpeed = Math.round((distanceToMove-distanceMoved+1)*finalSpeed);

                                                      distanceMoved += currentSpeed;

                                                      contentHold._x += dir*currentSpeed;

                                                      if (Math.abs(distanceMoved-distanceToMove)<=1) {

                                                                      contentHold._x = maskMovie._x-currentPosition+dir*distanceToMove;

                                                                      currentPosition = input._x;

                                                                      startFlag = false;

                                                                      delete this.onEnterFrame;

                                                      }

                                      };

                      }

      };

       

      nav.b1.onRelease = function() {

                      menuSlide(contentHold.content1);

      };

      nav.b2.onRelease = function() {

                      menuSlide(contentHold.content2);

      };

      nav.b3.onRelease = function() {

                      menuSlide(contentHold.content3);

      };

      nav.b4.onRelease = function() {

                      menuSlide(contentHold.content4);

      };

      nav.b5.onRelease = function() {

                      menuSlide(contentHold.content5);

      };

       

      nav.b6.onRelease = function() {

                      menuSlide(contentHold.content3);

      };

        • 1. Re: Action Script Buttons Heirarchy Help
          kglad Adobe Community Professional & MVP

          do the buttons nav.b1 etc have anything to do with the buttons you discussed?

          • 2. Re: Action Script Buttons Heirarchy Help
            onlinegenie Level 1

            No, the nav.b1 are the buttons on the home page or main scene to call the content 1. I want buttons inside the content1 to work for example e.g. i created a button to call this function this

             

            For example if i wanted to have the b1 button within the content2 page rather than the main scene page to call content 1 slide page, i have put the code directly on the button but still doesnt like it, currently they work just by the instance name and no action script on the buttons

             

            I have tried this

            on(release){
            nav.b1.menuSlide("content2");
            }

            • 3. Re: Action Script Buttons Heirarchy Help
              Ned Murphy Adobe Community Professional & MVP

              If those buttons you have that code attached to are inside other movieclips, and the nav movieclip is not, but it resides on the main timeline, then your best bet may be to add a _root reference to the button code...

               

              on(release){
                   _root.nav.b1.menuSlide("content2");
              }

              • 4. Re: Action Script Buttons Heirarchy Help
                onlinegenie Level 1

                Tried the _root still no luck im afraid..

                Will try and explain the current layout better.

                Index.swf – holds the splash page and frame of the site and through an external swf loader calls the content.swf page in. (this is the page that has the action script in  for the slide menu etc) each content1, content 2, conten3 movie clips slide in when called via b1, b2 or b3 buttons linked with the instance to the content.swf actionscript.

                 

                 

                • 5. Re: Action Script Buttons Heirarchy Help
                  kglad Adobe Community Professional & MVP

                  and i'm still not sure what you're doing.  but if there's a button b1 in content2 and you want to call menuSlide(), then on the same timeline as your current code use:

                   

                  contentHold.content2.b1.onRelease=function(){

                  menuSlide(this._parent);

                  }

                  • 6. Re: Action Script Buttons Heirarchy Help
                    onlinegenie Level 1

                    Thanks, but that didnt work for me I did manage to get one button working from within the content1 movieclip  by using the script below.

                     

                    on(release){
                    this._parent._parent._parent.container.loadMovie("video.swf");
                    }

                     

                     

                    Just trying to get the code i posted in my first message to work with a button in content 1. I have tried amending the code on the root page from:

                     

                     

                    nav.b1.onRelease = function() {
                        menuSlide(contentHold.content2);
                    };

                     

                    TO

                     

                    this._parent._parent._parent.nav.b1.onRelease = function() {
                        menuSlide(contentHold.content2);
                    };

                     

                     

                    STILL NO LUCK the button instance is b1 , I have even tried adding the script directly to a button.....its driving me crazy...thanks for all your help so far..

                     

                    on(release){
                    this._parent._parent._parent.contentHold.content2.b1.menuSlide(this._parent);
                    }

                    • 7. Re: Action Script Buttons Heirarchy Help
                      kglad Adobe Community Professional & MVP

                      you shouldn't attach code to objects.

                       

                      attach the following to the timeline where you want to place your code:

                       

                      trace("timeline "+this);

                       

                      attach the follwing to the timeline that contains the button you want to use:

                       

                      trace("button timeline "+b1);

                       

                      and attach the following to the timeline that contains menuSlide():

                       

                      trace("menuSlide "+this)

                       

                       

                      copy and paste the output in a message.

                      • 8. Re: Action Script Buttons Heirarchy Help
                        onlinegenie Level 1

                        ok, Output message is:

                         

                        action script added to the main time line page is: timeline _level0.CORE

                         

                        action script added to the main time line page is: menuSlide _level0.CORE

                         

                        action script added to the button page: button timeline _level0.CORE.contentHold.content2.b1

                         

                        if it helps I have found the original tutorial i used

                         

                        http://www.kirupa.com/developer/flash8/slidingMenu.htm

                         

                        the only change i have made was to contain the navigation buttons with an instance name "nav" and name the whole scene content.swf and load it into a different index.swf

                         

                        Cheers for your help so far....I didnt even no about this trace facility

                        • 9. Re: Action Script Buttons Heirarchy Help
                          onlinegenie Level 1

                          actually adding it to the main index.swf the output was this

                           

                          timeline _level0

                           

                          menuSlide _level0.page_mc.myLoader.CORE

                           

                          button timeline _level0.page_mc.myLoader.CORE.contentHold.content2.b1

                          • 10. Re: Action Script Buttons Heirarchy Help
                            kglad Adobe Community Professional & MVP

                            so, on your main timeline where you want to place your code use:

                             

                            this.page_mc.myLoader.CORE.contentHold.content2.b1.onRelease=function(){

                            //this._parent._parent._parent.menuSlide(whatever you want to pass here);

                            this._parent._parent._parent.menuSlide(this._parent);  // would pass this.page_mc.myLoader.CORE.contentHold.content2

                            }

                            • 11. Re: Action Script Buttons Heirarchy Help
                              onlinegenie Level 1

                              Hi, I feel we are sooo close...

                               

                               

                              Wasnt sure what you meant by the second part of the qutoted out partI have tried this so far:

                              // would pass this.page_mc.myLoader.CORE.contentHold.content2.......Sorry i am being abit slow with this. I wish i had time to sit and run through it myself but goto get it finished...been doing abit of a trial and error method...

                               

                               

                               

                              this.page_mc.myLoader.CORE.contentHold.content2.b1.onRelease=function(){ // IS THIS WHERE THE BUTTON IS LOCATED?
                                  this._parent._parent._parent.menuSlide(content4);  // AND IS THIS THE FUNCTION IM CALLING?
                              };

                               

                               

                              this.page_mc.myLoader.CORE.b1.onRelease = function() {
                                  this._parent._parent._parent.menuSlide(contentHold.content2);
                              };

                              • 12. Re: Action Script Buttons Heirarchy Help
                                kglad Adobe Community Professional & MVP

                                try:

                                 

                                this.page_mc.myLoader.CORE.contentHold.content2.b1.onRelease=function(){

                                this._parent._parent._parent.menuSlide(this._parent);

                                }

                                1 person found this helpful
                                • 13. Re: Action Script Buttons Heirarchy Help
                                  onlinegenie Level 1

                                  This still didnt work for me, so because i got a loadMovie AS  to work i took out the four page and had them load in as separate SWF files. A longer way, but at least i still have some hair left on my head!!

                                   

                                  Thanks kglad for all your help you pointed me in the right direction......

                                  • 14. Re: Action Script Buttons Heirarchy Help
                                    kglad Adobe Community Professional & MVP

                                    you're welcome.