In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

スライダー

これの元になったものがhttp://wonderfl.net/c/a6fIドラッグで移動するブロック
youtubePlayer
http://wonderfl.net/c/pdfhに使っています。
Get Adobe Flash player
by kururu99 16 Oct 2010
/**
 * Copyright kururu99 ( http://wonderfl.net/user/kururu99 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/t8Xk
 */

package {
    import flash.events.*;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    public class Main extends Sprite {
        public function Main():void {
            stage.scaleMode=StageScaleMode.NO_SCALE;
            stage.align=StageAlign.TOP_LEFT;
            var dragger:Dragger = new Dragger(200,130,40,40); 
            this.addChild(dragger);
            dragger.x = 100;
            dragger.y = 10;
            
            var dragger2:Dragger = new Dragger(240,30,80,30,0x0099ff,"dataX");
            this.addChild(dragger2);
            dragger2.x = 10;
            dragger2.y = 200;

            var dragger3:Dragger = new Dragger(240,30,70,30,0x009933,"dataX");
            this.addChild(dragger3);
            dragger3.x = 10;
            dragger3.y = 160;
            dragger3.setValue(12);

            var dragger4:Dragger = new Dragger(240,30,90,30,0xCC0000,"dataX");
            this.addChild(dragger4);
            dragger4.x = 10;
            dragger4.y = 240;
            dragger4.value = 12;
            dragger4.setValue(88);
            dragger4.setMax(88);
            dragger4.addEventListener(Event.CHANGE, function():void { trace(dragger4.value); } );
            
            var dragger5:Dragger = new Dragger(240,30,30,30,0x333399,"dataX");
            this.addChild(dragger5);
            dragger5.x = 10;
            dragger5.y = 280;
            dragger5.addEventListener(Event.CHANGE, function():void { trace(dragger5.value); } );
            dragger5.setValue(50);
            
            var dragger6:Dragger = new Dragger(30,160,30,30,0x333399,"dataY");
            this.addChild(dragger6);
            dragger6.x = 290;
            dragger6.y = 160;
            
            var dragger7:Dragger = new Dragger(30,160,30,40,0xCC0000);
            this.addChild(dragger7);
            dragger7.x = 330;
            dragger7.y = 160;
            
            var dragger8:Dragger = new Dragger(30,160,30,40);
            this.addChild(dragger8);
            dragger8.x = 370;
            dragger8.y = 160;
        }
    }
}
import flash.events.*;
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.display.Stage;
import flash.text.TextField;

class Dragger extends Sprite {
    private var draggBg:Sprite;
    private var draggBar:Sprite;
    private var MaxWidth:int;
    private var MaxHeight:int;
    private var Text:TextField;
    private var dataType:String;
    public var value:int=0;
    public function Dragger(Bgwidth:int=200, Bgheight:int=100,width:int=100, height:int=100,color:uint=0x0099ff,Type:String="nodata"):void {
        Text= new TextField();
        Text.text = "0";
        Text.x = 5;
        Text.y = 5;
        Text.width = 80;
        Text.height = 20;
        Text.selectable = false;
        dataType = Type;
        this.addChild(Text);
        draggBg = getBox(0xcccccc,Bgwidth,Bgheight);
        this.addChild(draggBg);
        draggBar = getBox(color,width,height);
        draggBg.addChild(draggBar);
        draggBar.addEventListener(Event.ENTER_FRAME,MoveScroll);
        setMax(100);
    }
    public function setValue(v:Number):void{
        draggBar.x = Math.floor((draggBg.width-draggBar.width)*v/100);
        trace("v"+v+"|"+draggBar.x);
    }
    public function setMax(v:Number):void{
        MaxWidth = draggBg.width*v/100;
        MaxHeight = draggBg.height*v/100;
        if(MaxHeight<draggBar.height){
            MaxHeight=draggBar.height;
        }
        if(MaxWidth<draggBar.width){
            MaxWidth=draggBar.width;
        }
    }
    private function getBox(color:uint,width:int=100, height:int=100,alpha:int=1):Sprite {
        var box:Sprite = new Sprite();
        box.graphics.beginFill(color,0.8);
        box.graphics.drawRoundRect(0, 0, width, height,10);
        box.graphics.endFill();
        return box;
    }
    private function MoveScroll(event:Event):void {
        removeEventListener(Event.ENTER_FRAME, MoveScroll);
        draggBar.addEventListener(MouseEvent.MOUSE_DOWN, scrollbarHandler);
        draggBg.addEventListener(MouseEvent.MOUSE_WHEEL,onScrollArea);
        draggBg.addEventListener(MouseEvent.CLICK, onScrollArea);
        stage.addEventListener(MouseEvent.MOUSE_UP, scrollbarUpHandler);
    }
    private function scrollbarHandler(event:Event):void {
        draggBar.addEventListener(Event.ENTER_FRAME, onScrollArea );
    }
    private function scrollbarUpHandler(event:Event):void {
        draggBar.removeEventListener(Event.ENTER_FRAME, onScrollArea );
    }
    private function onScrollArea(event) {

        if (event.type=="mouseWheel") {
            draggBar.x+=event.delta*-3;
            draggBar.y+=event.delta*-3;
        } else {
            draggBar.x=(stage.mouseX-this.x)-draggBar.width/2;
            draggBar.y=(stage.mouseY-this.y)-draggBar.height/2;
        }
        if (draggBar.x<0) {
            draggBar.x=0;
        }
        if (draggBar.y<0) {
            draggBar.y=0;
        }
        if (draggBar.x>MaxWidth-draggBar.width) {
            draggBar.x=MaxWidth-draggBar.width;
        }
        if (draggBar.y>MaxHeight-draggBar.height) {
            draggBar.y=MaxHeight-draggBar.height;
        }
        this.dispatchEvent(new Event(Event.CHANGE));
        if (dataType=="dataX") {
            Text.text = String(Math.floor(draggBar.x/(MaxWidth-draggBar.width)*100)+"%");
            value = Math.floor(draggBar.x/(MaxWidth-draggBar.width)*100);
        } else if (dataType=="dataY") {
            Text.text = String(Math.floor(draggBar.y/(MaxHeight-draggBar.height)*100)+"%");
        } else {
            Text.text = "";
        }
    }
}