/**
* Copyright tepe ( http://wonderfl.net/user/tepe )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/4yyh
*/
package {
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
var s:scroolBar = new scroolBar();
addChild(s);
s.x = 200;
RelativeLayout.setPos(stage, s, "rt");
}
}
}
//スクロールバー
import flash.display.*;
import flash.events.*;
import flash.text.*;
import caurina.transitions.Tweener;
class scroolBar extends Sprite{
private var s1:Sprite;//スライダー
private var s2:Sprite;//スクロールバー
private var s3:Sprite;//ベース
private var c1:uint = 0xcccccc;
private var c2:uint = 0x3355ff;
private var c3:uint = 0xdddddd;
private var c4:uint = 0xffffff;
public function scroolBar():void{
s3 = new Sprite();
s1 = new Sprite();
s1.graphics.lineStyle(0,c1);
s1.graphics.beginFill(c2);
s1.graphics.drawRect(0,0,10,400);
s1.graphics.endFill();
s3.addChild(s1);
s2 = new Sprite();
s2.graphics.lineStyle(0,c1);
s2.graphics.beginFill(c3);
s2.graphics.drawRect(0,0,10,200);
s2.graphics.endFill();
s3.addChild(s2);
addChild(s3);
x2 = s3.x;
//s3.addEventListener(MouseEvent.MOUSE_OVER,onOver);
//s3.addEventListener(MouseEvent.MOUSE_OUT,onOut);
s2.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
s2.addEventListener(MouseEvent.MOUSE_UP,onUp);
s2.addEventListener(MouseEvent.MOUSE_OVER,barOver);
}
private function barOver(e:MouseEvent):void{
s2.removeEventListener(MouseEvent.MOUSE_OVER,barOver);
s2.addEventListener(MouseEvent.MOUSE_OUT,barOut);
s2.graphics.clear();
s2.graphics.lineStyle(0,c1);
s2.graphics.beginFill(c4);
s2.graphics.drawRect(0,0,10,200);
s2.graphics.endFill();
}
private function barOut(e:MouseEvent):void{
s2.addEventListener(MouseEvent.MOUSE_OVER,barOver);
s2.removeEventListener(MouseEvent.MOUSE_OUT,barOut);
s2.graphics.clear();
s2.graphics.lineStyle(0,c1);
s2.graphics.beginFill(c3);
s2.graphics.drawRect(0,0,10,200);
s2.graphics.endFill();
}
private var my:Number=0;
private var y2:Number=0;
private function onDown(e:MouseEvent):void{
//s2.addEventListener(Event.MOUSE_LEAVE,onUp);
//s2.removeEventListener(MouseEvent.MOUSE_UP,onUp);
addEventListener(MouseEvent.MOUSE_MOVE,onMove);
my=s3.mouseY;
y2=s2.y;
}
private function onUp(e:MouseEvent):void{
removeEventListener(MouseEvent.MOUSE_MOVE,onMove);
}
private function onMove(e:MouseEvent):void{
s2.y = y2+s3.mouseY-my;
if(s1.y>s2.y)s2.y = s1.y;
if(s2.y+s2.height>s1.height)s2.y = s1.height-s2.height;
}
private var x2:Number;
private function onOver(e:MouseEvent):void{
//アニメーション処理
var scale:Number = 2;
Tweener.addTween(s3, {
time: 0.5, // アニメーション時間
x:x2+s3.width-s3.width*scale,
scaleX: scale, // s の scaleX を 指定値 まで遷移
//scaleY: scale, // s の scaleY を 指定値 まで遷移
alpha: 1,//不透明率
transition: "easeOutBack"//バウンドアニメーション
});
}
private function onOut(e:MouseEvent):void{
var scale:Number = 1;
Tweener.addTween(s3, {
x:x2,
time: 0.5, // アニメーション時間
scaleX: scale, // s の scaleX を 指定値 まで遷移
//scaleY: scale, // s の scaleY を 指定値 まで遷移
alpha: 1,//不透明率
transition: "easeInBack"//バウンドアニメーション
});
}
}
import flash.display.DisplayObject;
import flash.display.Stage;
import flash.geom.Point;
import flash.geom.Rectangle;
class RelativeLayout extends DisplayObject {
private static var aimX:int;
private static var aimY:int;
private static var _x:int;
private static var _y:int;
private static var _width:uint;
private static var _height:uint;
private static var rectangle:Rectangle;
public static function setPos(stage:Stage,$scope:DisplayObject,position:String="center",marginX:int=0,marginY:int=0,w:uint=0,h:uint=0):void {
if ($scope == null) {
return;
}
RelativeLayout.setSize($scope,w,h);
switch (position) {
case "center" :
case "cm" :
RelativeLayout.aimX = Math.floor(stage.stageWidth / 2 - RelativeLayout._width / 2) + marginX;
RelativeLayout.aimY = Math.floor(stage.stageHeight / 2 - RelativeLayout._height / 2) + marginY;
break;
case "top" :
case "ct" :
RelativeLayout.aimX = Math.floor(stage.stageWidth / 2 - RelativeLayout._width / 2) + marginX;
RelativeLayout.aimY = marginY;
break;
case "right" :
case "rm" :
RelativeLayout.aimX = Math.floor(stage.stageWidth - RelativeLayout._width) - marginX;
RelativeLayout.aimY = Math.floor(stage.stageHeight / 2 - RelativeLayout._height / 2) + marginY;
break;
case "bottom" :
case "cb" :
RelativeLayout.aimX = Math.floor(stage.stageWidth / 2 - RelativeLayout._width / 2) + marginX;
RelativeLayout.aimY = Math.floor(stage.stageHeight - RelativeLayout._height) - marginY;
break;
case "left" :
case "lm" :
RelativeLayout.aimX = marginX;
RelativeLayout.aimY = Math.floor(stage.stageHeight / 2 - RelativeLayout._height / 2) + marginY;
break;
case "righttop" :
case "rt" :
RelativeLayout.aimX = Math.floor(stage.stageWidth - RelativeLayout._width) - marginX;
RelativeLayout.aimY = marginY;
break;
case "rightbottom" :
case "rb" :
RelativeLayout.aimX = Math.floor(stage.stageWidth - RelativeLayout._width) - marginX;
RelativeLayout.aimY = Math.floor(stage.stageHeight - RelativeLayout._height) - marginY;
break;
case "leftbottom" :
case "lb" :
RelativeLayout.aimX = marginX;
RelativeLayout.aimY = Math.floor(stage.stageHeight - RelativeLayout._height) - marginY;
break;
case "lefttop" :
case "lt" :
default :
RelativeLayout.aimX = marginX;
RelativeLayout.aimY = marginY;
break;
}
RelativeLayout.point($scope, RelativeLayout.aimX, RelativeLayout.aimY);
}
public static function resize($scope:DisplayObject,w:uint=0,h:uint=0):void {
if ($scope == null) {
return;
}
RelativeLayout.setSize($scope,w,h);
$scope.width = RelativeLayout._width;
$scope.height = RelativeLayout._height;
}
public static function point($scope:DisplayObject,posX:int,posY:int):void {
if ($scope == null) {
return;
}
RelativeLayout.setPoint(posX, posY);
$scope.x = RelativeLayout._x;
$scope.y = RelativeLayout._y;
}
public static function rect($scope:DisplayObject,posX:int,posY:int,w:uint=0,h:uint=0):void {
if ($scope == null) {
return;
}
RelativeLayout.setPoint(posX, posY);
RelativeLayout.setSize($scope,w,h);
RelativeLayout.rectangle = new Rectangle(
RelativeLayout._x,RelativeLayout._y,RelativeLayout._width,RelativeLayout._height
);
$scope.x = RelativeLayout.rectangle.x;
$scope.y = RelativeLayout.rectangle.y;
$scope.width = RelativeLayout.rectangle.width;
$scope.height = RelativeLayout.rectangle.height;
}
private static function setSize($scope:DisplayObject,w:uint, h:uint):void {
w ? RelativeLayout._width = w:RelativeLayout._width = $scope.width;
h ? RelativeLayout._height = h:RelativeLayout._height = $scope.height;
}
private static function setPoint(posX:int,posY:int):void {
RelativeLayout._x = posX;
RelativeLayout._y = posY;
}
}