| Updated on | |
|
Below is an example of the code in action. Scroll down for the ActionScript.
Note: Put your mouse over the green triangle, left click and hold the button down, pull down. And now for the Flash MX ActionSctipt.
/*
Flash MX ActionScript Pully
Author: Douglas Palovick
Version: 1.0
License: GPL http://www.gnu.org/licenses/gpl.txt
*/
stop();
MovieClip.prototype.c2 = function(startX,
startY,
throughX,
throughY,
endX,endY){
var controlX = (2 * throughX) - .5 * (startX + endX);
var controlY = (2 * throughY) - .5 * (startY + endY);
this.lineTo(startX,startY);
this.curveTo(controlX,controlY,endX,endY);
};
function aquireBounds(mc) {
_root.s = this[mc].getBounds(_root);
_root.goo = _root.s.xMin;
_root.boo = _root.s.yMax;
};
aquireBounds('foo')
_root.attachMovie('pully_mc','bar',8);
_root.attachMovie('pully4_mc','bar1',9);
function redraw(mc_pully_base,mc_pully,mc_curve) {
_root.createEmptyMovieClip(mc_curve, 6);
_root[mc_pully_base]._x = ((_root.s.xMin + _root.s.xMax) / 2);
_root[mc_pully_base]._y = (_root.s.yMax);
_root[mc_pully]._x = ((_root.s.xMin + _root.s.xMax) / 2);
_root[mc_pully]._y = (_root.s.yMax);
_root[mc_curve].lineStyle(4);
_root[mc_curve].beginFill(0x990000,100);
_root[mc_curve].lineStyle(4);
_root[mc_curve].moveTo(_root.s.xMax,_root.boo);
_root[mc_curve].lineTo(_root.s.xMax,_root.s.yMin);
_root[mc_curve].lineTo(_root.s.xMin,_root.s.yMin);
_root[mc_curve].lineTo(_root.s.xMin,_root.boo);
_root[mc_curve].lineTo(s.xMax,_root.boo);
_root[mc_pully].onMouseUp = function() {
this.stopDrag();
this.onEnterFrame = function() {stop();};
_root.redraw(mc_pully_base,mc_pully,mc_curve);
};
_root[mc_pully].onPress = function() {
this.startDrag(false,((_root.s.xMin + _root.s.xMax) / 2),
(_root.s.yMax + 120),
((_root.s.xMin + _root.s.xMax) / 2),
(_root.s.yMax));
this.onEnterFrame = function() {
_root[mc_pully_base]._y = (_root[mc_pully]._y);
_root[mc_curve].clear();
_root[mc_curve].beginFill(0x990000,100);
_root[mc_curve].lineStyle(4);
_root[mc_curve].moveTo(_root.s.xMax,_root.boo);
_root[mc_curve].lineTo(s.xMax,s.yMin);
_root[mc_curve].lineTo(_root.s.xMin,_root.s.yMin);
_root[mc_curve].lineTo(_root.s.xMin,_root.boo);
_root[mc_curve].c2(_root.goo,_root.boo ,
_root[mc_pully_base]._x,
_root[mc_pully_base]._y,
_root.s.xMax,_root.boo);
_root[mc_curve].endFill;
};
};
};
redraw('bar','bar1','curve_mc2');
I purposely did not include the .fla file. You have the code and the end result, make it work :). |