Hi
I’m having a problem with my following situation: I made a class “Scrollbar” which I can use to create a scrollbar for a certain movieclip.
This movieclip extended class (Scrollbar) has 3 movieclips (see code below):
1 - which has the complete scrollbar[INDENT]1.1 - which has the background for the scrollbar
1.2 - which has the slider for the scrollbar
[/INDENT]Now, I’m trying to make an onPress handler inside my class, I tried to override the onPress() handler of the MovieClip class but it doesn’t work for my situation I think.
I’ll post my complete class here, any comments (also those that doesn’t have to do with my problem) are welcome since I started programming OO in ActionScript a few days ago.
class Scrollbar extends MovieClip{
private var contentArea_mc:MovieClip;
private var scrollbar_mc:MovieClip;
private var scrollbarBackground_mc:MovieClip;
private var scrollbarSlider_mc:MovieClip;
/**
* Constructor
*/
public function Scrollbar(numScrollbars:Number){
/**
* Make the scrollbar movieclip
*/
scrollbar_mc = _root.createEmptyMovieClip("scrollbar_" + numScrollbars, _root.getNextHighestDepth());
/**
* Add a background
*/
scrollbarBackground_mc = scrollbar_mc.createEmptyMovieClip("scrollbarBackground", scrollbar_mc.getNextHighestDepth());
with (scrollbarBackground_mc) {
//lineStyle(2, 0x000000, 100);
beginFill(0xCCCCCC);
moveTo(-10, 0);
lineTo(-10, 100);
lineTo(10, 100);
lineTo(10, 0);
lineTo(-10, 0);
endFill();
}
/**
* Add the slider
*/
scrollbarSlider_mc = scrollbar_mc.createEmptyMovieClip("scrollbarSlider", scrollbar_mc.getNextHighestDepth());
with (scrollbarSlider_mc) {
//lineStyle(2, 0x000000, 100);
beginFill(0x000000);
moveTo(-10, 0);
lineTo(-10, 100);
lineTo(10, 100);
lineTo(10, 0);
lineTo(-10, 0);
endFill();
}
trace("Vertical scrollbar created");
}
/**
* Set the content area to scroll
*/
public function setContentArea(content_mc:MovieClip){
this.contentArea_mc = content_mc;
trace("Scrollbar content area set to: " + this.contentArea_mc);
}
/**
* Update the scaling of the scrollbar
*/
public function updateScaling(){
updatePosition();
var numScale:Number = contentArea_mc._height / Stage.height;
// Hide or display the scrollbar
if(numScale > 1){
scrollbar_mc._visible = true;
} else {
scrollbar_mc._visible = false;
};
// Position the scrollbar relatively by using the current position of the content area
if(contentArea_mc._y <= 0){
var numScrollbarOffset:Number = Math.abs(contentArea_mc._y) / numScale;
scrollbarSlider_mc._y = numScrollbarOffset;
} else {
trace("! Error: The content area its Y position is larger than 0 (there is an offset from top border) !");
}
// Set the height
scrollbarSlider_mc._height = Stage.height / numScale;
}
/**
* Update the positioning of the scrollbar
*/
public function updatePosition(){
scrollbar_mc._x = Stage.width - scrollbar_mc._width/2;
scrollbar_mc._y = 0;
scrollbarBackground_mc._height = Stage.height;
}
}