Solved

HOW DO I ADD DRAGGABILITY TO THIS CURRENT CODE

Posted on 2003-11-30
3
207 Views
Last Modified: 2010-04-03
How do I add draggability to the code below.  I have a small thumbnail and a small magnifying glass that designates the zoom area.  The zoom of the thumbnail appears in another box.  Right now if you click on the thumbnail, the magnifying glass will move to the position you clicked.  How do I change the code so that you can both click the thumbnail to move to that position and be able to drag the magnifying glass around as well?  Here's the code on the magnifying glass.


onClipEvent (load) {
      // Initialize variables
      danX = _root.screen._x-(_root.screen._width/2);
      danY = _root.screen._y-(_root.screen._height/2);
      //
      //
      // negative one creates opposite direction to corrospond to the moviement of the viewfinder
      ratio = (_root.screen2._width/_root.screen._width)*(-1);
      //
      //
      // Change this number to speed up (less than 5) or slow down (greater than 5)
      speedRatio = 10;
      //
      //
      // Define function to do all the work
      function myClick (myX, myY) {
            xDis = ((myX-this._x)/speedRatio);
            yDis = ((myY-this._y)/speedRatio);
            //
            //
            // Make blur effect
            _root.screen2.blur._alpha = ((Math.abs(xDis)+Math.abs(yDis))*5);
            //
            //
            // Give Viewfinder elasticity
            _root.viewFinder._x = _root.viewFinder._x+xDis;
            _root.viewFinder._y = _root.viewFinder._y+yDis;
            _root.screen2._x = ((_root.viewFinder._x-_root.screen._x)*ratio)+(_root.window._x);
            _root.screen2._y = ((_root.viewFinder._y-_root.screen._y)*ratio)+(_root.window._y);
      }
}
onClipEvent (mouseUp) {
      // Set parameters for your function
      if (_root.screen.hitTest(_root._xmouse, _root._ymouse, true)) {
            danX = _root._xmouse;
            danY = _root._ymouse;
      }
}
onClipEvent (enterFrame) {
      // Call function
      myClick(danX, danY);
}

Any help would greatly be appreciated
0
Comment
Question by:madasczik
  • 2
3 Comments
 
LVL 27

Expert Comment

by:negatyve
ID: 9848822
I do not understand. THIS movieclip should be draggable?
0
 

Author Comment

by:madasczik
ID: 9851422
It sort of drags but it looks like its sticking to the start position and the click points for some reason.   Take a look:

http://dev.fusionapps.com/matt/thumbnail_zoom.html
http://dev.fusionapps.com/matt/thumbnail_zoom.swf
http://dev.fusionapps.com/matt/thumbnail_zoom.fla
0
 
LVL 27

Accepted Solution

by:
negatyve earned 500 total points
ID: 9851713
Modify the viewFinder button script this way:

on (press) {
      tellTarget ("../zoom") {
            gotoAndPlay(1);
      }
      call("reset");
      this.draggin = true;
      gotoAndPlay("start");
}
on (release) {
      tellTarget ("../zoom") {
            gotoAndStop("over");
      }
      call("reset");
      this.draggin = false;
      gotoAndPlay(1);
}
on (releaseOutside) {
      this.draggin = false;
      gotoAndPlay(1);
}
on (rollOver) {
      tellTarget ("../zoom") {
            gotoAndStop("over");
      }
      call("reset");
}
on (rollOut) {
      tellTarget ("../zoom") {
            gotoAndPlay(1);
      }
      call("reset");
}


then modify viewFinder script this way:


onClipEvent (load) {
      danX = _root.screen._x-(_root.screen._width/2);
      danY = _root.screen._y-(_root.screen._height/2);
      // negative one creates opposite direction to corrospond to the moviement of the viewfinder
      ratio = (_root.screen2._width/_root.screen._width)*(-1);
      // Change this number to speed up (less than 5) or slow down (greater than 5)
      speedRatio = 10;
      // Define function to do all the work
      function myClick (myX, myY) {
            xDis = ((myX-this._x)/speedRatio);
            yDis = ((myY-this._y)/speedRatio);
            // Make blur effect
            _root.screen2.blur._alpha = ((Math.abs(xDis)+Math.abs(yDis))*5);
            // Give Viewfinder elasticity
            _root.viewFinder._x += xDis;
            _root.viewFinder._y += yDis;
            _root.screen2._x = ((_root.viewFinder._x-_root.screen._x)*ratio)+(_root.window._x);
            _root.screen2._y = ((_root.viewFinder._y-_root.screen._y)*ratio)+(_root.window._y);
      }
}
onClipEvent (enterFrame) {
      // Call function
      myClick(danX, danY);
}
onClipEvent(mouseMove){
      if(this.draggin){
            if (_root.screen.hitTest(_root._xmouse, _root._ymouse, true)) {
                  danX = _root._xmouse;
                  danY = _root._ymouse;
            }
      }
}
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question