5 Replies Latest reply on Jun 13, 2010 4:34 PM by chrcha26

    Please answer. I've been trying for 2 days

    chrcha26 Level 1

      Newb here. I don't even know what you would call this effect, so it's difficult for me to find any info. I've tried using event listeners and defined functions, but I think I need to add some math. I've only been using flash for a about a week. I looked into it about a year ago, mainly tinkering with animation.

       

      I'm using AS3

      My flash file contains one panoramic image, and 2 layers named, actions and Background. I give the panoramic image an instance name of bg_mc. Each layer has one frame. I'm trying to make the bg_mc move along the x, opposite the mouse, and stop before leaveing the stage. I want to make the motion ease in/out. I do not want it to move in the y direction. My bg_mc is (w)2132 x (h)608 and the stage is (w) 1080 x (h) 608. I posted a day ago, but I don't think I was clear with the question.

       

      The closest I've come so far is getting the bg_mc to follow my mouse everywhere:(

        • 1. Re: Please answer. I've been trying for 2 days
          kglad Adobe Community Professional & MVP

          use:

           

          paramF(bg_mc,0,0,stage.stageWidth,stage.stageWidth-bg_mc.width);

           

          this.addEventListener(MouseEvent.MOUSE_MOVE,startLoopF);

           

          function startLoopF(e:Event){
              if(!this.hasEventListener(Event.ENTER_FRAME)){
                  this.addEventListener(Event.ENTER_FRAME,loopF);
              }
          }

           

          function loopF(e:Event){
              var destX:Number = bg_mc.m*mouseX+bg_mc.b;
              bg_mc.x = .5*bg_mc.x+.5*destX;
              if(Math.abs(bg_mc.x-destX)<1){
                  this.removeEventListener(Event.ENTER_FRAME,loopF);
              }
          }

           

          function paramF(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number){
              mc.m = (y1-y2)/(x1-x2);
              mc.b = y1-mc.m*x1;
          }

          • 2. Re: Please answer. I've been trying for 2 days
            chrcha26 Level 1

            Thanks a lot. I really appreciate that. It worked 100%. I didn't have to change anything. I’ve been burning through tuts on Lynda, but I haven't made it that far yet. Thanks again.

            • 3. Re: Please answer. I've been trying for 2 days
              chrcha26 Level 1

              Is there anyway to ease the motion in and out, so it's not so sensitive to the mouse movement?

              • 4. Re: Please answer. I've been trying for 2 days
                kglad Adobe Community Professional & MVP

                this adds a speed parameter to control easing:

                 

                // use a number from 0 to 1.  closer to 1, faster the easing

                var speed:Number = .1; 

                paramF(bg_mc,0,0,stage.stageWidth,stage.stageWidth-bg_mc.width);

                 

                this.addEventListener(MouseEvent.MOUSE_MOVE,startLoopF);

                 

                function startLoopF(e:Event){
                    if(!this.hasEventListener(Event.ENTER_FRAME)){
                        this.addEventListener(Event.ENTER_FRAME,loopF);
                    }
                }

                 

                function loopF(e:Event){
                    var destX:Number = bg_mc.m*mouseX+bg_mc.b;
                    bg_mc.x = (1-speed)*bg_mc.x+speed*destX;
                    if(Math.abs(bg_mc.x-destX)<1){
                        this.removeEventListener(Event.ENTER_FRAME,loopF);
                    }
                }

                 

                function paramF(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number){
                    mc.m = (y1-y2)/(x1-x2);
                    mc.b = y1-mc.m*x1;
                }

                • 5. Re: Please answer. I've been trying for 2 days
                  chrcha26 Level 1

                  Thanks again! That was exactly what I was looking for. I'll try to post a link here in the next couple days so you can see the final project.