My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package com.dLibs.utils
{
import com.greensock.TweenLite;

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;

public class dragIt extends MovieClip
{
private var _mc :MovieClip = new MovieClip();
private var _mk :MovieClip = new MovieClip();
private var zoomin :MovieClip;
private var zoomout :MovieClip;
private var _mouseOut :Boolean;
private var xScaleOld :Number;
private var yScaleOld :Number;
private var iScale :Number;
private var newWidth :Number;
private var newHeight :Number;
private var so :scaleObject;

public function dragIt()
{
// Dont use it XD
}

public function drag(mc:MovieClip, mk:MovieClip, resized:Boolean = false):void
{
_mc = mc;
_mk = mk;
// @
_mc.x = _mk.x;
_mc.y = _mk.y;
// @
_mc.mask = _mk; // set Image masked
_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragMc);
_mc.addEventListener(MouseEvent.MOUSE_UP, unDragMc);
// Change the scale ?
if ( resized ) so = new scaleObject(_mc, { width: _mk.width, height: _mk.height });
}

/** Init and Stop the Dragger */

private function dragMc(m:MouseEvent):void
{
_mouseOut = false;

_mc.startDrag();
//_mc.addEventListener(Event.ENTER_FRAME, verifyArraste);
trace("StartDrag");
}

private function unDragMc(m:MouseEvent):void
{
_mc.stopDrag();
_mc.removeEventListener(Event.ENTER_FRAME, verifyArraste);
if ( !_mouseOut ) verifyArraste();
trace("DragOut");
}

/** Adding zooming option */

public function addZoom(_zoomin:MovieClip, _zoomout:MovieClip, scaleQuant:Number = 0.1):void
{
// iScale is the scale value
iScale = scaleQuant;
// Set the functions to zoom in and out
zoomin = _zoomin;
zoomout = _zoomout;
zoomin.addEventListener(MouseEvent.CLICK, moreZoom);
zoomout.addEventListener(MouseEvent.CLICK, lessZoom);
}

private function moreZoom(m:MouseEvent):void
{
zoomout.addEventListener(MouseEvent.CLICK, lessZoom);
// record the actual scale x and y
xScaleOld = _mc.scaleX;
yScaleOld = _mc.scaleY;
// Set the new scale
TweenLite.to(_mc, 0.5, { scaleX : (xScaleOld + iScale), scaleY : (yScaleOld + iScale), onUpdate : verifyDrag, onUpdateParams : [null], onComplete : verifyDrag });
}

private function lessZoom(m:MouseEvent):void
{
// record the actual scale x and y
xScaleOld = _mc.scaleX;
yScaleOld = _mc.scaleY;
// get the width and height
newWidth = _mc.width;
newHeight = _mc.height;
// Set the new scale
// TweenLite.to(_mc, 0.5, { scaleX : (xScaleOld - iScale), scaleY : (yScaleOld - iScale), onUpdate : verifyDrag, onUpdateParams : [null] });
TweenLite.to(_mc, 0.5, { scaleX : (xScaleOld - iScale), scaleY : (yScaleOld - iScale), onUpdate : verifyBoth });
}

/** Move Objects ******************************************/

public function addMovement(up:MovieClip, right:MovieClip, down:MovieClip, left:MovieClip):void
{
up.addEventListener(MouseEvent.CLICK, MoveUp);
right.addEventListener(MouseEvent.CLICK, MoveRight);
down.addEventListener(MouseEvent.CLICK, MoveDown);
left.addEventListener(MouseEvent.CLICK, MoveLeft);
}

private function MoveUp(e:MouseEvent):void
{
TweenLite.to(_mc, 0.5, { y : _mc.y - 50, onUpdate : verifyArraste });
}

private function MoveRight(e:MouseEvent):void
{
TweenLite.to(_mc, 0.5, { x : _mc.x + 50, onUpdate : verifyArraste });
}

private function MoveDown(e:MouseEvent):void
{
TweenLite.to(_mc, 0.5, { y : _mc.y + 50, onUpdate : verifyArraste });
}

private function MoveLeft(e:MouseEvent):void
{
TweenLite.to(_mc, 0.5, { x : _mc.x - 50, onUpdate : verifyArraste });
}

/** Verify the limits of the dragger ***********************/

private function verifyBoth():void
{
verifyDrag();
verifyArraste();
}

private function verifyArraste(e:Event = null):void
{
// If exit the mask space
if ( _mc.stage.mouseX > _mk.x + _mk.width || _mc.stage.mouseX < _mk.x || _mc.stage.mouseY < _mk.y || _mc.stage.mouseY > _mk.y + _mk.height )
{
_mouseOut = true;
_mc.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_UP));
}

if ( _mc.x > _mk.x ) TweenLite.to(_mc, 0.5, { x : _mk.x });
if ( _mc.x < (( _mk.x + _mk.width) - _mc.width ) ) TweenLite.to(_mc, 0.5, { x : (( _mk.x + _mk.width) - _mc.width ) });
if ( _mc.y > _mk.y ) TweenLite.to(_mc, 0.5, { y : _mk.y });
if ( _mc.y < (( _mk.y + _mk.height ) - _mc.height ) ) TweenLite.to(_mc, 0.5, { y : (( _mk.y + _mk.height ) - _mc.height ) });
}

private function verifyDrag(e:Event = null):void
{
// verify content width and height
if ( _mc.width < _mk.width || _mc.height < _mk.height )
{
zoomout.removeEventListener(MouseEvent.CLICK, lessZoom);
so = new scaleObject(_mc, { width: _mk.width, height: _mk.height });
_mc.x = _mk.x;
_mc.y = _mk.y;
}

} // End Functions

} // End Class

} // End Package

Change log

r26 by pablodavi on Feb 4, 2010   Diff
[No log message]
Go to: 
Sign in to write a code review

Older revisions

r12 by pablodavi on Apr 16, 2009   Diff
[No log message]
r11 by pablodavi on Apr 16, 2009   Diff
Added zoom option into the dragIt.as
r10 by pablodavi on Apr 13, 2009   Diff
dragIt.as added
All revisions of this file

File info

Size: 5190 bytes, 166 lines
Powered by Google Project Hosting