Solved

HOW DO I ADD DRAGGABILITY TO THIS CURRENT CODE

Posted on 2003-11-30
3
205 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
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.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

762 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now