ScrollBar
/**
* Copyright macomputer ( http://wonderfl.net/user/macomputer )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/t6pe
*/
package {
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.Graphics;
import flash.events.*;
import flash.geom.Rectangle
[SWF(backgroundColor="#FFFFFF", frameRate=30, width=600, height=600)]
public class ScrollBar extends Sprite {
public function ScrollBar() {
//スクロールバー
var barMc:Sprite = new Sprite();
var bar:Shape = new Shape();
barMc.addChild(bar);
stage.addChild(barMc);
var barGraphics:Graphics = bar.graphics;
barGraphics.lineStyle(1, 0x000000, 0);
barGraphics.beginFill(0x000000, 1.0);
barGraphics.drawRect ( 0, 0 , 10 , 100);
barMc.x = 450;
barMc.y = 100;
//コンテンツ
var conMc:Sprite = new Sprite();
var con:Shape = new Shape();
conMc.addChild(con);
stage.addChild(conMc);
var conGraphics:Graphics = con.graphics;
conGraphics.lineStyle(1, 0x000000, 0);
conGraphics.beginFill(0x000000, 1.0);
conGraphics.drawRect ( 0, 0 , 300 , 600);
conMc.x = 100;
conMc.y = 100;
barMc.buttonMode = true;
barMc.addEventListener(MouseEvent.MOUSE_DOWN, barDown);
function barDown(e:MouseEvent):void{
e.target.startDrag(false, new Rectangle(450,100,0,300));
barMc.addEventListener(MouseEvent.MOUSE_UP, barUp);
stage.addEventListener(MouseEvent.MOUSE_UP, barUp);
}
function barUp(e:MouseEvent):void{
barMc.stopDrag();
barMc.removeEventListener(MouseEvent.MOUSE_UP, barUp);
stage.removeEventListener(MouseEvent.MOUSE_UP, barUp);
}
}
}
}