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

スケールバーとスクロールバー

あと、もうちょっと詰める予定。
以外と大変ですね。あたまくらくらしています。
Get Adobe Flash player
by kawamura 14 Feb 2011
    Embed
/**
 * Copyright kawamura ( http://wonderfl.net/user/kawamura )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/nMBM
 */

package  {
    import flash.display.MovieClip;
    public class Main extends MovieClip {
        public function Main() {
            // constructor code
            var loader:XMLLoader = new XMLLoader();
            loader.init(this);
            
        }
        public function initload_complete(xml:XML):void{
        //public function initload_complete(data_ar:Array):void{
            var body:Body=new Body();
            addChild(body);
            //body.init(data_ar);
            body.init(xml);
        }
    }
    
}

class XMLLoader {
    private var path:String ="data.xml";
    private var main:Main;
    public function XMLLoader() {
        // constructor code
    }
    public function init(_main:Main):void{
        main=_main;
        var xml:XML = <data>
 <month id="1">
  <title color="0x00FF00" src="img/001.jpg">test</title>
  <title color="0xFF0000" src="img/002.jpg">test</title>
  <title color="0xFF0000" src="img/003.jpg">test</title>

 </month>
 <month id="2">
  <title color="0xFF0000">test</title>
  <title color="0x0000FF">test</title>
  <title color="0xFF0000">test</title>
  <title color="0x00FF00">test</title>
  <title color="0xFF0000">test</title>
 </month>
 <month id="3">
  <title color="0xFF0000">test</title>
  <title color="0xFF0000">test</title>
 </month>
 <month id="4">
  <title color="0x0000FF">test</title>
  <title color="0xFF0000">test</title>
  <title color="0x00FF00">test</title>
 </month>
 <month id="5">
  <title color="0xFF0000">テキストです。</title>
 </month>
 <month id="6">
  <title color="0xFF0000">testtesttesttesttesttest</title>
  <title color="0x00FF00">test</title>
  <title color="0x0000FF">test</title>
 </month>
 <month id="7">
  <title color="0xFF0000" src="img/001.jpg">testtest</title>
  <title color="0xFF00FF">testtesttest</title>
  <title color="0x00FF00">test</title>
  <title color="0x0000FF">test</title>
  <title color="0x0000FF">test</title>
  <title color="0xFF0000" src="img/002.jpg">test</title>
  <title color="0xCC0000">test</title>
 </month>
 <month id="8">
  <title color="0xFF00FF">test</title>
  <title color="0xFF0000">test</title>
  <title color="0x00FF00">test</title>
 </month>
 <month id="9">
  <title color="0xFF0000">test</title>
  <title color="0x0000FF">test</title>
  <title color="0xFF0000">test</title>
  <title color="0xFF0000">test</title>
  <title color="0x0000FF">test</title>
 </month>
 <month id="10">
  <title color="0xFF0000">test</title>
  <title color="0x00FF00">test</title>
 </month>
 <month id="11">
  <title color="0xFF0000">test</title>
  <title color="0x0000FF">test</title>
  <title color="0xFF0000">test</title>
 </month>
 <month id="12">
  <title color="0xFF0000">test</title>
  <title color="0xFF0000">test</title>
  <title color="0x0000FF">test</title>
  <title color="0xFF0000">test</title>
  <title color="0xFF0000">test</title>
  <title color="0xFF0000">test</title>
 </month>
</data>
        main.initload_complete(xml);
    }
}



import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Graphics;
import flash.events.MouseEvent;

class Body extends MovieClip {
    private var slider:TimeSlider;
    private var calendar:Calendar;
    private var scrollbar:Scrollbar;
    private var target_height:Number;
    public function Body() {
        // constructor code
    }
    public function init(xml:XML):void{
        slider=new TimeSlider();
        addChild(slider);
        slider.init();
        slider.x=30;
        slider.y=400;
        calendar = new Calendar();
        addChild(calendar);
        calendar.init(xml);
        calendar.x=30;
        calendar.y=30;
        
        scrollbar=new Scrollbar();
        addChild(scrollbar);
        scrollbar.init();
        scrollbar.x=30;
        scrollbar.y=340
        
        slider.setCalendar(calendar);
        scrollbar.setCalendar(calendar);
        calendar.setReferences(slider,scrollbar);
    }
}

import flash.display.MovieClip;
import flash.display.Graphics;
import flash.display.Shape;
import flash.text.TextField;
import flash.events.Event;

class Calendar extends MovieClip {
    //カレンダー位置
    public var position:Number = 0;
    //1ヶ月:0 6ヶ月:1 12ヶ月:2
    public var type:uint=2;
    //長さ
    private var width_list:Array=new Array(30,60,360);
    //
    private var month_list:Vector.<Month>;
    private var month_width:Number;
    private var base:MovieClip;
    private var slider:TimeSlider;
    private var scrollbar:Scrollbar;
    //
    private var target_x:Number=0;

    public function Calendar() {
        // constructor code
    }
    public function init(xml:XML):void{
        var i:uint;
        var g:Graphics;
        var waku:Shape=new Shape();
        waku.graphics.lineStyle(2,0x000000);
        waku.graphics.drawRect(0,0,360,300);
        addChild(waku);
        var mask_shape:Shape=new Shape();
        g=mask_shape.graphics;
        //g.lineStyle(2,0x000000);
        g.beginFill(0x000000)
        g.drawRect(0,0,360,300)
        

        addChild(mask_shape);
        base = new MovieClip();
        addChild(base);
        base.mask=mask_shape;
        //
        var red:MovieClip=new MovieClip();
        red.graphics.beginFill(0xFF0000,0.6);
        red.graphics.drawCircle(0,0,5)
        red.y=-5;
        red.x=0;
        base.addChild(red);
        //
        var month:Month;
        month_width=width_list[0];
        month_list=new Vector.<Month>();
        for(i=0;i<12;i++){
            month = new Month();
            month.x = month_width*i-month_width*6;
            month.init( i , month_width , xml.month[i])
            base.addChild(month);
            
            month_list.push(month);
        }
        //
        base.x=180;
        addEventListener(Event.ENTER_FRAME,enter_frame);
    }
    public function resizePosition(value:Number):void{
        if(value == 0){
            position = 0;
            scrollbar.resizePosition(0);
        }else if(value==1){

            if(type == 0){
                position = 3 ;
                
            }else if(type == 2){
                position = position-3 ;
                if(position<0){
                    position = 0;
                }else if(position >6){
                    position = 6;
                }
            }
            scrollbar.resizePosition(1);
        }else if(value==2){
            position = position+3 ;
            scrollbar.resizePosition(2);
        }
        
    }
    public function get barwidth():Number{
        return month_width;
        //return 360*360/(month_width*12);
    }
    public function get barx():Number{
        return base.x ;
    }
    public function setReferences(_slider:TimeSlider,_scrollbar:Scrollbar):void{
        slider=_slider;
        scrollbar=_scrollbar;
    }
    private function enter_frame(event:Event):void{
        var target_width:Number = width_list[slider.target_x/100];
        var dw:Number=target_width-month_width;
        month_width+=dw*0.6;
        var g:Graphics;
        var i:uint;
        for(i=0;i<12;i++){
            var month:Month = month_list[i];
            month.resize_bg(month_width)
            month.x= month_width*i-month_width*6;;
        }
        //
        //trace(position)
        target_x =-1 * month_width * position + month_width*6; ;
        var dx:Number = target_x-base.x;
        base.x+=dx*0.6;
    }
}

import flash.display.MovieClip;
import flash.display.Graphics;
import flash.events.Event;
import flash.geom.Rectangle;
import flash.events.MouseEvent;

class TimeSlider extends MovieClip {
    public var target_x:Number=0;
    //
    private var btn:MovieClip;
    private var line:MovieClip;
    private var dx:Number;
    private var calendar:Calendar;
    private var drag_flag:Boolean = false;
    
    public function TimeSlider() {
        // constructor code
    }
    
    public function init():void{
        var g:Graphics;

        line=new MovieClip();
        addChild(line);
        g=line.graphics;
        g.lineStyle(3,0,1);
        g.moveTo(0,0);
        g.lineTo(200,0);
        g.endFill();
        g.moveTo(0,15);
        g.lineTo(0,-15);
        g.endFill();
        g.moveTo(100,12);
        g.lineTo(100,-12);
        g.endFill();
        g.moveTo(200,15);
        g.lineTo(200,-15);
        g.endFill();

        
        btn=new MovieClip();
        btn.x=0;
        addChild(btn);
        g=btn.graphics;
        g.beginFill(0);
        g.drawRoundRect(-10,-10,20,20,10,10);
        btn.addEventListener(MouseEvent.MOUSE_DOWN,btn_mousedown);
        btn.buttonMode=true;
    }
    public function setCalendar(_calendar:Calendar):void{
        calendar=_calendar;
        addEventListener(Event.ENTER_FRAME,calendar_enterframe);
        
    }
    private function calendar_enterframe(event:Event):void{
        if(drag_flag){
            if(this.mouseX<50){
                if(target_x != 0){
                    setPosition(0);
                }
                calendar.type = 0;
                target_x=0;
                
            }else if(this.mouseX < 150){
                if(target_x != 100){
                    setPosition(1);
                }
                calendar.type = 1;
                target_x=100;
            }else{
                if(target_x != 200){
                    setPosition(2);
                }
                calendar.type = 2;
                target_x=200;
            }
            var dx:Number=target_x-btn.x;
            btn.x+=dx*0.7;
        }
    }
    private function setPosition( value:Number):void{
        
        calendar.resizePosition(value)
    }
    private function btn_mousedown(event:Event):void{
        //var btn:MovieClip=MovieClip(event.currentTarget);
        stage.addEventListener(MouseEvent.MOUSE_UP,btn_mouseup);
        btn.alpha=0.6;
        drag_flag = true;
    }
    private function btn_mouseup(event:Event):void{
        //btn.stopDrag();
        stage.removeEventListener(MouseEvent.MOUSE_UP,btn_mouseup);
        btn.alpha=1.0
        drag_flag = false;
    }
    
}


import flash.display.MovieClip;
import flash.display.Graphics;
import flash.display.Shape;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;

class Scrollbar extends MovieClip{
    private var bar:MovieClip;
    
    private var target_x:Number = 180;
    private var calendar:Calendar;
    private var drag_flag:Boolean=false;
    private var drag_x:Number = 0;
    private var bar_x:Number=0
    
    
    public function Scrollbar() {
        // constructor code
    }
    public function init():void{
        var g:Graphics;
        
        var bg:Shape=new Shape();
        addChild(bg);
        g=bg.graphics;
        g.lineStyle(2,0x000000);
        g.drawRect(0,0,360,20);
    }
    public function setCalendar(_calendar:Calendar):void{
        calendar = _calendar;
        //
        bar=new MovieClip();
        addChild(bar);
        

        var bar_width:Number=360*360/(calendar.barwidth*12);
        bar.x=bar_width*0.5;
        setBarWidth(bar_width);
        bar.buttonMode = true;
        bar.addEventListener(MouseEvent.MOUSE_DOWN,bar_mousedown);
        /*
        var red:MovieClip=new MovieClip();
        red.graphics.beginFill(0xFF0000,0.6);
        red.graphics.drawCircle(0,0,5)
        red.y=-5;
        red.x=0;
        
        bar.addChild(red);
        */
        //
        addEventListener(Event.ENTER_FRAME,enterframe);
    }
    public function resizePosition(value:Number):void{
        var bar_width:Number;
        var d_width:Number;
        if(value==0){
            bar_width = 360;
            target_x = bar_width*0.5;;

        }else if(value == 1){
            bar_width = 360*360/(60*12);
            d_width = (360-bar_width)/6;
            target_x= calendar.position * d_width+bar_width*0.5;
            
        }else if(value == 2){
            bar_width = 360*360/(360*12);
            d_width =  (360-bar_width)/12;
            target_x= calendar.position * d_width+bar_width*0.5;
        }
        setBarWidth(bar_width);
    }
    private function enterframe(event:Event):void{
        var bar_width:Number=360*360/(calendar.barwidth*12);
        var d_width:Number;
        var i:uint;
        
        if(drag_flag){
            if(calendar.type == 0){
                target_x = bar_width*0.5;
                
            }else if(calendar.type==1){
                d_width = (360-bar_width)/6;
                for(i=0 ; i<7 ;i++){
                    if( bar_x +(this.mouseX-drag_x) < (0.5+i)*d_width + bar_width*0.5){
                        target_x=i*d_width+bar_width*0.5;
                        calendar.position = i;
                        break;
                    }
                }
            }else if(calendar.type==2){
                d_width = (360-bar_width)/11;
                for(i=0 ; i<12 ;i++){
                    if( bar_x +(this.mouseX-drag_x) < (0.5+i)*d_width + bar_width*0.5){
                        target_x=i*d_width+bar_width*0.5;
                        calendar.position = i;
                        break;
                    }
                }
            }
        }
        //bar.x=target_x
        var dx:Number=target_x-bar.x;
        bar.x+=dx*0.5;
        setBarWidth(bar_width);
    }
    private function bar_mousedown(event:MouseEvent):void{
        drag_x = this.mouseX;
        bar_x = target_x;
        drag_flag=true;
        //
        /*
        var rect:Rectangle=new Rectangle(0,0,360-bar.width,0);
        bar.startDrag(false,rect);
        */
        stage.addEventListener(MouseEvent.MOUSE_UP,bar_mouseup);
    }
    private function bar_mouseup(event:MouseEvent):void{
        drag_flag=false;
        //bar.stopDrag();
        
        stage.removeEventListener(MouseEvent.MOUSE_UP,bar_mouseup);
    }
    private function setBarWidth(bar_width:Number):void{
        var g:Graphics=bar.graphics;
        g.clear();
        g.beginFill(0x000000);
        g.drawRect(bar_width*-0.5,0,bar_width,20);
    }
}



import flash.display.MovieClip;
import flash.text.TextField;
import flash.display.Graphics;

class Month extends MovieClip{
    private var bg_mc:MovieClip;
    private var bg_g:Graphics;
    private var masu_list:Vector.<Masu>;
    private var width_list:Array=[30-4,60-4,360-4]
    public function Month() {
        // constructor code
    }
    public function init(number:Number,month_width:Number ,  xml:XML):void{
        bg_mc = new MovieClip();
        addChild(bg_mc);
        bg_g = bg_mc.graphics;
        bg_g.lineStyle(1,0);
        bg_g.beginFill(0xCCCCCC,0.5);
        bg_g.drawRect(0,0,month_width,300);
        addChild(bg_mc);
        var tf:TextField=new TextField();
        addChild(tf);
        tf.text=String(number+1);
        //
        var masu:Masu;
        var i:uint;
        var n:Number = xml.title.length();
        masu_list =new Vector.<Masu>();
        var g:Graphics;
        var masu_width:Number=month_width-4;
        for (i=0 ; i<n ; i++){
            masu=new Masu();
            addChild(masu);
            var color:Number = Number(xml.title[i].@color);
            var title_string:String=String(xml.title[i]);
            masu.init(masu_width,color,title_string);
            masu.x=2;
            masu.y=300-(month_width * (i+1))+2;
            masu_list.push(masu);
        }
    }
    public function resize_bg(month_width:Number):void{
        bg_g.clear();
        bg_g = bg_mc.graphics;
        bg_g.lineStyle(1,0);
        bg_g.beginFill(0xCCCCCC,0.5);
        bg_g.drawRect(0,0,month_width,300);
        
        
        var masu:Masu;
        var g:Graphics;
        var i:uint;
        var n:Number = masu_list.length;
        var masu_width:Number=month_width-4;
        for (i=0 ; i<n ; i++){
            masu = masu_list[i];
            masu.resize_bg(masu_width);

        }
        
    }

}

import flash.display.MovieClip;
import flash.display.Graphics;
import flash.text.TextField;
import flash.display.BitmapData;
import flash.display.Bitmap;

class Masu extends MovieClip{
    private var bg_mc:MovieClip=new MovieClip();
    private var mask_mc:MovieClip;
    private var mask_g:Graphics
    private var g:Graphics;
    private var _color:Number;
    private var tf_mc:MovieClip
    
    
    public function Masu() {
        // constructor code
    }
    public function init(masu_width:Number, color:Number,value:String):void{
        _color =color;
        //
        mask_mc = new MovieClip();
        addChild(mask_mc);
        mask_g = mask_mc.graphics;
        mask_g.beginFill(0xFF0000);
        mask_g.drawRect(0,0,masu_width,26)
        this.mask=mask_mc;
        
        //
        bg_mc=new MovieClip();
        addChild(bg_mc);
        g=bg_mc.graphics;
        g.beginFill(_color);
        g.drawRect(0,0,masu_width,26);
        tf_mc = new MovieClip();
        addChild(tf_mc);
        var tf:TextField=new TextField();
        tf.text=value;
        tf.width=tf.textWidth+4;
        tf.height=tf.textHeight+5;
        
        var bmd:BitmapData=new BitmapData(tf.width,tf.height,true,0xFFFFFF);
        bmd.draw(tf,null,null,null,null,true);
        var bm:Bitmap=new Bitmap(bmd,"auto",true);
        tf_mc.addChild(bm)
        bm.x = tf.width * -0.5;
        
        if(tf_mc.width>masu_width){
            tf_mc.x=tf_mc.width*0.5;
        }else{
            tf_mc.x=masu_width*0.5;
        }
    }
    public function resize_bg(value:Number):void{
        mask_g.clear();
        mask_g.beginFill(0xFF0000);
        mask_g.drawRect(0,0,value,26)
        //
        g.clear();
        g.beginFill(_color);
        g.drawRect(0,0,value,26);
        
        if(tf_mc.width>value){
            tf_mc.x=tf_mc.width*0.5;
        }else{
            tf_mc.x=value*0.5;
        }
    }
}