Hi Guys,
I'm completely lost about a problem i'm having with a AS3 class i've developed. I've been searching for a solution over the internet but i couldn't find anything to throw some light over my problem. I also tried different approaches, but the problem still occurs.
I'll try to be very clear with this issue so if anyone has ever had this problem, can help me (pleeeeaaaaaase

)
----
I have a class i use to scroll a movieclip.
I create an instance of this class using the following code:
Code:
var scroll:ScrollContent = new ScrollContent(stage);
scroll.setContent(movieClipToScroll);
scroll.init();
What ScrollContent does, is to draw the scrolling components, create a mask, apply it to the movieClipToScroll movieclip and then takes care of the scrolling itself when you drag one of the sprites.
I'll explain the code I'm using here below:
Code:
public class ScrollContent extends MovieClip {
//var declarations
public var mcReel:Sprite;
private var track:Sprite;
private var scroller:Sprite;
private var buttonUp:Sprite;
private var buttonDown:Sprite;
private var msk:Sprite;
private var deltaScroll, deltaText, delta:Number
private var trackWidth:Number = 16;
private var trackHeight:Number = 400;
private var scrollerHeight:Number = 50;
private var min = 16;
private var max = 380;
public var maskWidth:Number = 320;
public var maskHeight:Number = 400;
private var ease:Number = .3;
private var _stage:Stage;
public function ScrollContent(ref:Stage) {
_stage = ref;
}
public function setContent(mc:MovieClip):void {
mcReel = mc;
}
public function init():void {
track = new Sprite();
scroller = new Sprite();
buttonUp = new Sprite();
buttonDown = new Sprite();
msk = new Sprite();
var scrollBar:Sprite = new Sprite();
scroller.buttonMode = scroller.useHandCursor = true;
drawElement(track, trackWidth, trackHeight, 0x6c8aaf, 1, 0xd8e4f0, 1);
drawElementGradient(buttonUp, trackWidth - 3, trackWidth - 3, 0x6c8aaf, 1, new Array(0x8ca6c4,0x9ab7d2), new Array(1,1), new Array(0,255));
drawElementGradient(buttonDown, trackWidth - 3, trackWidth - 3, 0x6c8aaf, 1, new Array(0x8ca6c4,0x9ab7d2), new Array(1,1), new Array(0,255));
drawElementGradient(scroller, trackWidth-3, scrollerHeight, 0x6c8aaf, 1, new Array(0x8ca6c4,0x9ab7d2), new Array(1,1), new Array(0,255));
drawElement(msk, maskWidth, maskHeight, 0x0,0,0xff0000,1);
track.x = maskWidth + 10;
track.y = 0;
buttonUp.x = track.x + 2;
buttonUp.y = track.y + 2;
buttonDown.x = track.x + 2;
buttonDown.y = track.y + trackHeight - trackWidth + 1;
scroller.x = track.x + 2;
scroller.y = min;
scrollBar.addChild(track);
scrollBar.addChild(buttonUp);
scrollBar.addChild(buttonDown);
scrollBar.addChild(scroller);
mcReel.parent.addChild(scrollBar);
mcReel.parent.addChild(msk);
mcReel.parent.addChild(this);
mcReel.mask = msk;
scroller.addEventListener(MouseEvent.MOUSE_DOWN, onPressEvent);
scroller.addEventListener(Event.ENTER_FRAME, enterFrame);
deltaText = mcReel.height - maskHeight;
deltaScroll = trackHeight - scrollerHeight - (2 * (trackWidth -3)) - 6;
delta = deltaText/deltaScroll;
}
private function enterFrame(e:Event) {
mcReel.y += (((min-scroller.y) * delta) - mcReel.y ) * ease;
}
private function onPressEvent(e:Event) {
_stage.addEventListener(MouseEvent.MOUSE_UP, onReleaseEvent);
scroller.startDrag(false, new Rectangle(scroller.x,min,0,deltaScroll));
}
private function onReleaseEvent(e:Event) {
stopDrag();
_stage.removeEventListener(MouseEvent.MOUSE_UP, onReleaseEvent);
}
private function drawElement(mc:Sprite, w:Number, h:Number, lc:uint, la:uint, fc:uint, fa:uint):void {
//drawRec solid color
}
private function drawElementGradient(mc:Sprite, w:Number, h:Number, lc:uint, la:uint, c:Array, a:Array, r:Array):void {
//drawRec gradient
}
}
----
As you can see in the code above, the
scroller sprite is the one that handles the real scrolling movement.
The problem is that the sensible area of this sprite, only seems to be a small portion of it, located in the top of the sprite, instead of the whole sprite itself, as it should. I can see that because when i MOUSE_OVER it, the hand cursor only appears in the top most 10px, instead of the whole 50pxs height. I also noticed that when you click on this 10px and start the dragging, the draggeable area stays just there, this means that the sprite, y coordinate changes, but the sensible area of it stays in the original position.
I tried different things to solve it, i made scroller a movieclip instead of a sprite, i made another sprite called hitArea and set it as the hitArea of scroller, I got rid of scrollBar sprite and added the remaining sprites directly as siblings of mcReel, but nothing seems to solve the problem.
Also, If i instantiate several times this class, it happens to change the sensible area randomly, that means the first instance has 10px sensible on scroller, the second one 40px, the third one none, etc.
Can anyone help me or tell me where could i find any documentation about something similar i can check to solve this?
Many, many many thanks!
Piero