Solved

HOW DO I ADD DRAGGABILITY TO THIS CURRENT CODE

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

912 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

16 Experts available now in Live!

Get 1:1 Help Now