Peepz,
Im building a scroll class which looks like this:
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.geom.Rectangle;
import flash.display.DisplayObjectContainer
import flash.display.MovieClip;
public class ContentScroller2 {
//eigen code
private var moveSpeed:Number
private var easingSpeed:Number
private var scrollHeight:Number
private var percentScrolled:Number
private var newY:Number
// how much of the movie can be scrolled
private var scrollable:Number
private var initContentPos:Number
// the drag positions that are possible for the mcDragger
private var left:Number
private var top:Number
private var right:Number
private var bottom:Number
private var scrollWheelSpeed:Number
private var _mcContent:Sprite
private var _mcMask:Sprite
private var _mcDragger:Sprite
private var _mcTrack:Sprite
private var dragBounds:Rectangle;
public function ContentScroller2(mcContent:Sprite, mcMask:Sprite, mcDragger:Sprite, mcTrack:Sprite, ease:Number, setDraggerSize:Boolean = false)
{
_mcContent = mcContent
_mcMask = mcMask
_mcDragger = mcDragger
_mcTrack = mcTrack
moveSpeed = 2;
easingSpeed = 5;
scrollHeight = _mcTrack.height ;
// how much of the movie can be scrolled
scrollable = Math.round(_mcContent.mcRegister.height - mcMask.height);
initContentPos = 12
// the drag positions that are possible for the mcDragger
left = _mcTrack.x;
top = _mcTrack.y + 26;
right = _mcTrack.x;
bottom = _mcTrack.height - _mcDragger.height + _mcTrack.y
scrollWheelSpeed = 30;
dragBounds = new Rectangle(_mcDragger.x, _mcDragger.y, 0, _mcTrack.height - _mcDragger.height);
initHorizontal();
}
private function initHorizontal():void
{
// before we do anything make sure the content is even scrollable, if it isn't hide everything and return
if (scrollable<0)
{
_mcDragger.visible = false;
_mcTrack.visible = false
//btnDown.enabled = false;
return;
_mcContent.removeEventListener(Event.ENTER_FRAME, updateContentPos);
}
else
{
addListeners();
}
}
private function addListeners():void {
_mcDragger.addEventListener(MouseEvent.MOUSE_DOWN, draggerDown);
_mcDragger.addEventListener(MouseEvent.MOUSE_UP, removeDraggerEvents);
}
private function draggerDown (me:MouseEvent):void {
_mcDragger.startDrag(false, dragBounds);
_mcDragger.addEventListener(MouseEvent.MOUSE_MOVE, draggerMouseMove);
//_mcContent.addEventListener(Event.ENTER_FRAME, updateContentPos);
}
private function draggerMouseMove (me:MouseEvent):void {
updateContentPos();
}
private function removeDraggerEvents (me:MouseEvent):void {
_mcContent.removeEventListener(Event.ENTER_FRAME, updateContentPos);
_mcDragger.removeEventListener(MouseEvent.MOUSE_MO VE, draggerMouseMove);
_mcDragger.stopDrag();
}
private function updateContentPos ():void
{
percentScrolled = (_mcDragger.y-top)/(scrollHeight-_mcDragger.height);
// instead of setting the _y property directly, we simple set newY
// that way we can adjust how we handle the new Y coordinate we'd like to move to
newY = Math.round(initContentPos-(percentScrolled*scrollable));
trace(percentScrolled)
_mcContent.y += Math.round((newY-_mcContent.y)/easingSpeed);
}
}
i have a code inside my total movie which contains the scroller, the code is:
var myContentScroller:ContentScroller2 = new ContentScroller2(mcContent, mcMask, mcDragger, mcTrack, 3, false)
All the clips like: mcContent, mcMask, mcDragger, mcTrack are on the stage.
To use this MC’s well i have to (or maybe not) i have to “re-assign” them in the package like (maybe there is a cleaner and better way?):
_mcContent = mcContent
_mcMask = mcMask
_mcDragger = mcDragger
_mcTrack = mcTrack
but now my final question is how can i target the movieClip “mcRegister” which is inside “mcContent” on the stage? (in AS1 it was like mcContent.mcRegister but that wont work.)
the code in the package is like:
scrollable = Math.round(_mcContent.mcRegister.height - mcMask.height);
Hope somebody can help me out!
Greetz!