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

バブルチャートのようなもの

ハンス・ロスリングのHIV考察: 新たな事実と驚愕のビジュアルデータ
http://www.ted.com/talks/lang/jpn/hans_rosling_the_truth_about_hiv.html

時間軸をつける前に、変な動きがついてしまいました。
Get Adobe Flash player
by kawamura 08 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/1s7Y
 */

package  {
    import flash.display.MovieClip;
    [SWF(width = "465", height = "465", backgroundColor = "0xFFFFFF", frameRate = "30")]
    public class Main extends MovieClip {
        public static var xml_path:String="data.xml"
        
        public function Main() {
            // constructor code
            var loader:XMLLoader=new XMLLoader();
            loader.init(xml_path,this);
        }
        public function xml_complete(xml:XML):void{
            var body:Body = new Body();
            body.init(xml);
            addChild(body);
        }
    }
}


class XMLLoader {
    private var main:Main;
    public function XMLLoader() {
        // constructor code
    }
    public function init(path:String,_main:Main):void{
        main=_main;
        var xml:XML=<data>
 <item id="0" value="30" x="30" y="10" color="0xCCDDDD" />
 <item id="1" value="20" x="20" y="25" color="0xFFDDDD" />
 <item id="2" value="60" x="25" y="20" color="0xCCDDFF" />
 <item id="3" value="40" x="28" y="10" color="0xCC00DD" />
 <item id="4" value="45" x="25" y="15" color="0x00DDDD" />
 <item id="5" value="40" x="25" y="22" color="0xCC00CC" />
 <item id="6" value="43" x="15" y="22" color="0xFF0033" />
 <item id="7" value="20" x="25" y="12" color="0x2222CC" />
 <item id="8" value="31" x="25" y="19" color="0x66FFCC" />
 <item id="9" value="33" x="28" y="23" color="0xCC3333" />
</data>
        main.xml_complete(xml);
    }
}

import flash.display.MovieClip;
class Body extends MovieClip {
    private var graph:Graph;
    private var plate:Plate;
    
    public function Body() {
        // constructor code
    }
    public function init(xml:XML):void{
        graph=new Graph();
        graph.init(xml,this);
        addChild(graph);
        graph.x=30;
        graph.y=150;
        //
        plate = new Plate();
        plate.init(xml,this);
        addChild(plate);
        plate.x=30;
        plate.y=10;
        
    }
    public function bubble_over(i:uint):void{
        plate.selected_number(i);
    }
    public function bubble_out():void{
        plate.mouseout_all();
    }
    public function btn_over(i:uint):void{
        graph.selected_number(i);
    }
    public function btn_out():void{
        graph.mouseout_all();
    }
}
    


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

class Plate extends MovieClip {
    private var btn_list:Vector.<MovieClip>;
    private var k:Number=0.5;
    private var u:Number=0.3;
    private var body:Body;
    
    public function Plate() {
        // constructor code
    }
    public function init(xml:XML,_body:Body):void{
        body=_body;
        //
        var i:uint;
        var n:uint=xml.item.length();
        btn_list=new Vector.<MovieClip>();
        for(i=0;i<n;i++){
            var node:XML=xml.item[i];
            var btn:MovieClip=new MovieClip();
            addChild(btn);
            var g:Graphics=btn.graphics;
            g.beginFill(node.attribute("color"),1);
            g.drawRect(0,0,100,20);
            btn.vs=0;
            btn.last_scale=1;
            btn.x=130*Math.floor(i/6);
            btn.y=22*(i%6);
            btn.addEventListener(Event.ENTER_FRAME,btn_enterframe);
            btn.addEventListener(MouseEvent.MOUSE_OVER,btn_mouseover);
            btn.addEventListener(MouseEvent.MOUSE_OUT,btn_mouseout);
            
            btn_list.push(btn);
        }
    }
    public function mouseout_all():void{
        var i:uint;
        var n:uint=btn_list.length;
        for(i=0;i<n;i++){
            var btn:MovieClip=btn_list[i];
            mouseout_move(btn);
        }
    }
    public function selected_number(value:uint):void{
        var i:uint;
        var n:uint=btn_list.length;
        for(i=0;i<n;i++){
            var btn:MovieClip=btn_list[i];
            if(i==value){
                mouseover_move(btn);
            }else{
                mouseout_move(btn);
            }
        }
    }
    private function btn_mouseover(event:MouseEvent):void{
        var btn:MovieClip=MovieClip(event.currentTarget);
        mouseover_move(btn);
        var i:uint;
        var n:uint=btn_list.length;
        for(i=0;i<n;i++){
            if(btn==btn_list[i]){
                body.btn_over(i);
                break;
            }
        }
    }
    private function mouseover_move(btn:MovieClip):void{
        setChildIndex(btn,this.numChildren-1);
        btn.last_scale=1.2;
    }
    private function btn_mouseout(event:MouseEvent):void{
        var btn:MovieClip=MovieClip(event.currentTarget);
        mouseout_move(btn);
        //
        body.btn_out();
    }
    private function mouseout_move(btn:MovieClip):void{
        btn.last_scale=1.0;
    }
    private function btn_enterframe(event:Event):void{
        var btn:MovieClip=MovieClip(event.currentTarget);
        var a_scale:Number=k*(btn.last_scale-btn.scaleX);
        btn.vs += a_scale-u*btn.vs;
        btn.scaleX  += btn.vs;
        btn.scaleY = btn.scaleX;
    }
}
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.utils.*;

class Graph extends MovieClip {
    private var body:Body;
    private var paper:Grid;
    private var bubble_list:Vector.<Bubble>;
    private var start_cnt:uint;
    private var start_id:uint;
    
    public function Graph() {
        paper=new Grid();
        paper.init();
        addChild(paper);
    }
    public function init(xml:XML,_body:Body):void{
        body=_body;
        var i:uint;
        var n:uint;
        bubble_list=new Vector.<Bubble>();
        n=xml.item.length();
        for(i=0;i<n;i++){
            var node:XML=xml.item[i];
            var bubble:Bubble=new Bubble()
            addChild(bubble);
            bubble.init(node.@value,node.@color);
            bubble.x=10*node.@x;
            bubble.y=300-10*node.@y;
            bubble_list.push(bubble);
        }
        start_cnt=0
        start_id=setTimeout(first_move,1000);
    }
    public function first_move():void{
        var bubble:Bubble=bubble_list[start_cnt++];
        bubble.addEvents();
        if(start_cnt<bubble_list.length){
            start_id=setTimeout(first_move,100);
        }
    }
    public function selected_number( value:uint):void{
        var i:uint;
        var n:uint=bubble_list.length;
        for(i=0;i<n;i++){
            var bubble:Bubble=bubble_list[i];
            if(i==value){
                mouseover_move(bubble);
            }else{
                mouseout_move(bubble);
            }
        }
    }
    public function mouseout_all():void{
        var i:uint;
        var n:uint=bubble_list.length;
        for(i=0;i<n;i++){
            var bubble:Bubble=bubble_list[i];
            mouseout_move(bubble)
        }
    }
    private function swapBubble(bubble:Bubble):void{
        setChildIndex(bubble,this.numChildren-1);
    }
    public function bubble_mouseover(bubble:Bubble):void{
        swapBubble(bubble);
        var i:uint;
        var n:uint=bubble_list.length;
        for(i=0;i<n;i++){
            if(bubble==bubble_list[i]){
                body.bubble_over(i);
                break;
            }
        }
    }
    private function mouseover_move(bubble:Bubble):void{
        swapBubble(bubble);
        bubble.mouseover();
    }
    public function bubble_mouseout():void{
        body.bubble_out();
    }
    private function mouseout_move(bubble:Bubble):void{
        //bubble.last_scale=1.0;
        bubble.mouseout();
    }
}
import flash.display.MovieClip;
import flash.display.Graphics;
class Grid extends MovieClip {
    public function Grid() {
        // constructor code
    }
    public function init():void{
        var g:Graphics=this.graphics;

        var i:uint;
        for(i=1;i<=40;i++){
            if(i%5==0){
                g.lineStyle(1,0x00CC66,1);
            }else{
                g.lineStyle(1,0x00CC66,0.2);
            }
            g.moveTo(10*i,300);
            g.lineTo(10*i,0);
            g.endFill();
        }
        for(i=1;i<=30;i++){
            if(i%5==0){
                g.lineStyle(1,0x00CC66,1);
            }else{
                g.lineStyle(1,0x00CC66,0.2);
            }

            g.moveTo(0,300-i*10);
            g.lineTo(400,300-i*10);
            g.endFill();
        }
        g.lineStyle(2,0x000000);
        g.moveTo(0,300);
        g.lineTo(0,0);
        g.endFill();
        g.moveTo(0,300);
        g.lineTo(400,300);
        g.endFill();
    }
}
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.*;
import flash.events.MouseEvent;


class Bubble extends MovieClip{
    private var vs:Number;
    private var ls:Number;
    private var k:Number=0.1;
    private var u:Number=0.1;
    private var circle:Sprite;
    private var radius:Number;
    private var fukidashi:Fukidashi;
    public function Bubble() {
        // constructor code
    }
    public function init(value:Number,color:Number):void{
        vs = 0;
        ls = 1;
        circle=new Sprite();
        circle.scaleX=0;
        circle.scaleY=0;
        addChild(circle);
        var g:Graphics=circle.graphics;
        g.beginFill(color,0.8);
        radius=value;
        g.drawCircle(0,0,value);
        fukidashi=new Fukidashi();
        fukidashi.init(String(color));
        addChild(fukidashi);
        fukidashi.x=radius*Math.cos(-0.25*Math.PI)
        fukidashi.y=radius*Math.sin(-0.25*Math.PI);;

    }
    public function addEvents():void{
        addEventListener(Event.ENTER_FRAME,enterframe);
        addEventListener(MouseEvent.MOUSE_OVER,bubble_mouseover);
        addEventListener(MouseEvent.MOUSE_OUT,bubble_mouseout);
    }
    public function mouseout():void{
        ls=1.0;
        fukidashi.ls=0.0;
    }
    public function mouseover():void{
        ls=1.2;
        fukidashi.ls=1.0;
    }
    private function bubble_mouseover(evetn:MouseEvent):void{
        MovieClip(this.parent).bubble_mouseover(this)
        mouseover();
    }
    private function bubble_mouseout(event:MouseEvent):void{
        MovieClip(this.parent).bubble_mouseout();
        mouseout();
    }
    private function enterframe(event:Event):void{
        var a_scale:Number=k*(ls-circle.scaleX);
        vs += a_scale-u*vs;
        circle.scaleX  += vs;
        circle.scaleY = circle.scaleX;
        radius=circle.width*0.5-10
        fukidashi.x=radius*Math.cos(-0.25*Math.PI);
        fukidashi.y=radius*Math.sin(-0.25*Math.PI);
    }
}

import flash.display.MovieClip;
import flash.display.Graphics;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.events.Event;
import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.geom.ColorTransform;
import flash.display.Bitmap;
class Fukidashi extends MovieClip {
    public var ls:Number;
    private var bg:MovieClip;
    public function Fukidashi() {
        // constructor code
    }
    public function init(str:String):void{
        var text_field:TextField=new TextField();
        var text_format:TextFormat=new TextFormat();
        text_format.color=0xFFFFFF;
        text_field.defaultTextFormat = text_format;
        text_field.text=str;
        text_field.width=text_field.textWidth+5;
        text_field.height=text_field.textHeight+2;
        var bmd:BitmapData=new BitmapData(Math.ceil(text_field.width),Math.ceil(text_field.height),true,0xFFFFFF);
        bmd.draw(text_field);
        var bm:Bitmap=new Bitmap(bmd,"auto",true);
        bm.x=5;
        bg=new MovieClip();
        var g:Graphics=bg.graphics;
        g.beginFill(0x333333);
        g.drawRoundRect(0,0,text_field.width+10,20,20,20);
        bg.y=-1*bg.height;
        bm.y=bg.y;
        var allow:MovieClip=new MovieClip();
        g=allow.graphics;
        g.beginFill(0x333333);
        g.moveTo(10,0);
        g.lineTo(20,0);
        var theta:Number=0.75*Math.PI;
        g.lineTo(15+15*Math.cos(theta),15*Math.sin(theta));
        addChild(allow);
        addChild(bg);
        addChild(bm);
        //
        this.scaleX=0;
        this.scaleY=0;
        ls=0;
        addEventListener(Event.ENTER_FRAME,enterframe);
    }
    private function enterframe(event:Event):void{
        var ds:Number=ls-this.scaleX;
        this.scaleX+=ds*0.5;
        this.scaleY=this.scaleX;
    }
}