I am using Lee Brimelow’s oop scrollbar.
http://www.gotoandlearn.com/play?id=72
This works on its own but when I try and load it as am external movieclip the scrollbar stops working.
my external swf is added to the stage and cast as a movieclip with.
var externalMovie = MovieClip(loader.content);
I think the line
stage.addEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
may be the problem. How do I reference the stage from an external MC?
Many thanks.
full as code below
package com.leebrimelow.ui
{
import flash.display.*;
import flash.events.*;
public class ScrollBar extends MovieClip
{
private var yOffset:Number;
private var yMin:Number;
private var yMax:Number;
public function ScrollBar():void
{
yMin = 0;
yMax = track.height - thumb.height;
thumb.addEventListener(MouseEvent.MOUSE_DOWN, thumbDown);
stage.addEventListener(MouseEvent.MOUSE_UP, thumbUp);
}
private function thumbDown(e:MouseEvent):void
{
stage.addEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
yOffset = mouseY - thumb.y;
}
private function thumbUp(e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
}
private function thumbMove(e:MouseEvent):void
{
thumb.y = mouseY - yOffset;
if(thumb.y <= yMin)
thumb.y = yMin;
if(thumb.y >= yMax)
thumb.y = yMax;
dispatchEvent(new ScrollBarEvent(thumb.y / yMax));
e.updateAfterEvent();
}
}
}
package com.leebrimelow.ui
{
import flash.events.*;
public class ScrollBarEvent extends Event
{
public static const VALUE_CHANGED = "valueChanged";
public var scrollPercent:Number;
public function ScrollBarEvent(sp:Number):void
{
super(VALUE_CHANGED);
scrollPercent = sp;
}
}
}
package com.leebrimelow.ui
{
import flash.display.*;
import flash.events.*;
import caurina.transitions.*;
public class ScrollBox extends MovieClip
{
public function ScrollBox():void
{
sb.addEventListener(ScrollBarEvent.VALUE_CHANGED, sbChange);
}
private function sbChange(e:ScrollBarEvent):void
{
Tweener.addTween(content, {y:(-e.scrollPercent*(content.height-masker.height)),
time:1});
}
}
}