18 Replies Latest reply on Oct 11, 2008 10:59 PM by kglad

    Slider control for movieclip.

    americancuervo Level 1
      Hello,
      I need some help with rotating different objects on stage by using a slider.

      What happens now is that as I choose one object, rotate it and then choose another object.
      The newly selected object rotates automatically to where the slider was previously moved to.
      What I want to be able to do is,
      as you choose one object, rotate it and move on to the next object.
      The slider will reset itself to the value that the object already has.
      So if the object was upside down and I selected it, the slider would move according to the rotation value of the object and not the other way around.

      Here is the code I am currently using,
      Thanks very much for any help you can provide.
        • 1. Re: Slider control for movieclip.
          kglad Adobe Community Professional & MVP
          wherever you choose objects (? choosePart() ), use:

          this._rotation = (this._rotation + 360) % 360;
          slider._x = this._rotation+300;
          • 2. Re: Slider control for movieclip.
            americancuervo Level 1
            Hi,
            Thanks kglad.

            I added the piece of code that you gave me and it almost works perfectly.

            It works for the first several times I choose a different object and then something happens.
            The newly chosen object begins to rotate without stopping.

            Any ideas why this would be happening,
            Thanks once again.
            • 3. Re: Slider control for movieclip.
              kglad Adobe Community Professional & MVP
              i suspect you're running into a problem with that onEnterFrame that never stops. you should add an if-statement:

              if(Math.abs(myRotation-slider._x+300)<1){
              myRotation=slider._x-300;
              delete this.onEnterFramel
              }

              and restart it in your slider.onPress handler.
              • 4. Re: Slider control for movieclip.
                americancuervo Level 1
                Thanks kglad,

                Is this how it should look?

                slider.onPress=function(){
                startDrag(slider, false, 300, 540, 660, 540 );
                onEnterFrame=function(){
                myRotation = (focus._rotation + 360) % 360;
                myRotation += (slider._x-300 - myRotation)/6;
                focus._rotation = myRotation;
                }
                }
                slider.onRelease=function(){
                stopDrag();
                }
                onEnterFrame=function(){
                myRotation = (focus._rotation + 360) % 360;
                myRotation += (slider._x-300 - myRotation)/6;
                focus._rotation = myRotation;
                if(Math.abs(myRotation-slider._x+300)<1){
                myRotation=slider._x-300;
                delete this.onEnterFrame
                }
                }

                Your help is much appreciated.
                • 5. Re: Slider control for movieclip.
                  kglad Adobe Community Professional & MVP
                  that's going to create a slider.onEnterFrame which could work, but you'll need to change some things:

                  • 6. Re: Slider control for movieclip.
                    americancuervo Level 1
                    Well,
                    Definitely eliminated the spinning out of control with
                    delete slider.onEnterFrame

                    But now it seems that the
                    delete slider.onEnterFrame is canceling out the rotation before it happens.

                    Thanks for your help.
                    • 7. Re: Slider control for movieclip.
                      kglad Adobe Community Professional & MVP
                      :

                      slider.onPress=function(){
                      startDrag(slider, false, 300, 540, 660, 540 );
                      this.onMouseMove=function(){
                      this.onEnterFrame=rotateF;
                      }
                      }
                      slider.onRelease=function(){
                      stopDrag();
                      delete this.onMouseMove;
                      }
                      • 8. Re: Slider control for movieclip.
                        americancuervo Level 1
                        Thank you very much kglad.
                        That took care of that problem.

                        Now I believe my last hurdle is
                        that if rotate the "object" more than 50%
                        and then click on the "object" again,
                        the "slider" jumps backwards to a negative _x value.
                        Then when I click on the "slider" it returns to its default value of 300, which in turn makes the"object" return to its default _rotation value as well.

                        Thanks for all the help.
                        • 9. Re: Slider control for movieclip.
                          kglad Adobe Community Professional & MVP
                          then "this" isn't in the scope of your object or you're not using the code i suggested. your code should look like:

                          object._rotation = (object._rotation + 360) % 360;
                          slider._x = object._rotation+300;
                          • 10. Re: Slider control for movieclip.
                            americancuervo Level 1
                            Thanks kglad,
                            I really appreciate all of the help.

                            Your code is doing exactly what I need it to do.
                            The only thing is that the "slider" reverts backwards after the rotation hits 50%.

                            If I set the "660" in
                            startDrag(slider, false, 300, 540, 660, 540 );
                            to "480",
                            startDrag(slider, false, 300, 540, 480, 540 );
                            It works perfectly, no problems what so ever.
                            It works like it should.

                            Maybe I have a problem with percentages?

                            This is the complete code I am currently using at the moment.

                            Thanks once again.

                            ////////////////////////////////////////////
                            var focus;
                            var partsList:Array = new Array(eyes, eyes2, eyes3, eyes4, eyes5, eyes6);
                            for (j in partsList) {
                            partsList[j].onPress = choosePart;
                            }
                            for (j in partsList) {
                            partsList[j].onRelease = unchoosePart;
                            }
                            function choosePart() {
                            focus = this;
                            this.focusEnabled = true;
                            Selection.setFocus(this);
                            this.startDrag();
                            this._rotation = (this._rotation + 360) % 360;
                            slider._x = this._rotation+300;

                            /*note:
                            focus._rotation = (focus._rotation + 360) % 360;
                            slider._x = focus._rotation+300;
                            Works the same.*/

                            }
                            function unchoosePart() {
                            focus = this;
                            this.stopDrag();
                            }
                            slider.onPress=function(){
                            startDrag(slider, false, 300, 540, 660, 540 );
                            this.onEnterFrame=rotateF
                            }
                            slider.onRelease=function(){
                            stopDrag();
                            }
                            function rotateF(){
                            myRotation = (focus._rotation + 360) % 360;
                            myRotation += (slider._x-300 - myRotation)/6;
                            focus._rotation = myRotation;
                            if(Math.abs(myRotation-slider._x+300)<1){
                            myRotation=slider._x-300;
                            delete slider.onEnterFrame
                            }
                            }
                            • 11. Re: Slider control for movieclip.
                              americancuervo Level 1
                              Here is a working model of what is going on.

                              http://www.americancuervo.com/rotate/index.html

                              The enlarge slider seems to more or less work using the very same code.

                              The rotate slider is the one with problems.

                              When you go over 50% you can see the effect it produces the next time you choose that same object.

                              Thank you very much.

                              • 12. Re: Slider control for movieclip.
                                kglad Adobe Community Professional & MVP
                                you don't need both these:

                                this._rotation = (this._rotation + 360) % 360;
                                slider._x = this._rotation+300;

                                /*note:
                                focus._rotation = (focus._rotation + 360) % 360;
                                slider._x = focus._rotation+300;

                                so, remove one. and use trace(slider._x) after the remaining code to see if slider is being assigned an _x property less than 300.
                                • 13. Re: Slider control for movieclip.
                                  americancuervo Level 1
                                  Hi kglad
                                  I removed those last lines of code
                                  focus._rotation = (focus._rotation + 360) % 360;
                                  slider._x = focus._rotation+300;

                                  and
                                  I used trace(slider._x).
                                  It reports the current position of the slider _x value until it gets to 481 and then it jumps backward 360 px and traces 121.
                                  So if I go to a full rotation 660 it jumps backwards to the beginning and traces 300.
                                  So it reports good things until it gets to 50%.

                                  What do you think?

                                  Thank you
                                  • 14. Re: Slider control for movieclip.
                                    kglad Adobe Community Professional & MVP
                                    there must be some other code affecting slider's _x property or something funny going on with your _rotation property.

                                    use trace(focus._rotation) or trace(this._rotation) just before slider._x is assigned.
                                    • 15. Re: Slider control for movieclip.
                                      americancuervo Level 1
                                      Thanks kglad,

                                      I put trace(focus._rotation)
                                      in

                                      function rotateF(){
                                      myRotation = (focus._rotation + 360) % 360;
                                      myRotation += (slider._x-300 - myRotation)/6;
                                      focus._rotation = myRotation;
                                      if(Math.abs(myRotation-slider._x+300)<1){
                                      myRotation=slider._x-300;
                                      trace(focus._rotation)
                                      delete slider.onEnterFrame
                                      }
                                      }

                                      And it showed that the problem lies within the _rotation property.

                                      It reports great up to 180 degrees and then as it should report 181 it skips back to -179.

                                      Somewhere my _rotation property is getting confused.
                                      • 16. Re: Slider control for movieclip.
                                        americancuervo Level 1
                                        I decided to run another test using different code So I could trace the _rotation property and try to get an accurate result.
                                        But!
                                        It still reported the same problem.
                                        It traces the degree of the _rotation great up until it gets to 180 degrees and then it jumps backwards to -179.

                                        What does this all mean?

                                        Thanks again for your help.

                                        Here is the different code I tested,

                                        slider.handle.onPress = function() {
                                        this.startDrag(true, slider.line._x-slider.handle._width/2, slider.line._y-slider.handle._height/2, slider.line._width-slider.handle._width/2, slider.line._y-slider.handle._height/2);
                                        }
                                        slider.handle.onRelease = slider.handle.onReleaseOutside = function() {
                                        this.stopDrag();
                                        }
                                        onEnterFrame = function() {
                                        focus._rotation = slider.line._x + slider.handle._x + slider.handle._width/2;
                                        trace(focus._rotation)
                                        }
                                        • 17. Re: Slider control for movieclip.
                                          americancuervo Level 1
                                          I found a solution,

                                          Thanks very much to you kglad.

                                          You are Awesome.

                                          function choosePart() {
                                          focus = this;
                                          this.focusEnabled = true;
                                          Selection.setFocus(this);
                                          this.startDrag();
                                          this.swapDepths( nextHighest );

                                          this._rotation = (this._rotation + 360) % 360;

                                          var rotationStation:Number = this._rotation;
                                          if (rotationStation < 0) {
                                          slider._x = this._rotation+660;
                                          }
                                          else {
                                          slider._x = this._rotation+300;
                                          }
                                          • 18. Re: Slider control for movieclip.
                                            kglad Adobe Community Professional & MVP
                                            you're welcome.