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 SoWhat1983 19 Dec 2009
    Embed
/**
 * Copyright SoWhat1983 ( http://wonderfl.net/user/SoWhat1983 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ucCS
 */

package {
	import flash.display.*;
	import flash.text.*;
	import flash.events.*;
    public class FlashTest extends Sprite {
    	
    	public var  CX:Number = stage.stageWidth/2;
    	public var  CY:Number = stage.stageHeight/2;
    	
        public function FlashTest() {
			inittrace(stage);
    		
            var t:DrgblText = new DrgblText('20:00','うんこ!');
            t.x =t.y = 100;
            t.addEventListener(Event.ENTER_FRAME,onLoop,false,0,true);
			addChild(t);
        	
            var t2:DrgblText = new DrgblText('15:30','起床');
            t2.x =t2.y = 200;
            t2.addEventListener(Event.ENTER_FRAME,onLoop,false,0,true);
            addChild(t2);
        }
        public function onLoop(e:Event):void {
			e.target.drawBorder(CX,CY);
        }
    }
}


import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.geom.*;
import caurina.transitions.Tweener;
import caurina.transitions.properties.*;
/*
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.tweens.ITween;
import org.libspark.betweenas3.events.TweenEvent;
import org.libspark.betweenas3.easing.*;*/

class DrgblText extends Sprite {
	
	private var t:TextField =new TextField();
	private var de:Sprite = new Sprite();
	private var frame:Sprite = new Sprite();
	private var bdr:Sprite = new Sprite();
	
	// コンストラクタ
	public function DrgblText(timeStr:String,titleStr:String) {
	
		//drawBorder
		addChild(bdr);
	    
	    // 楕円
	    drawE();
	    addChild(de);
	    
		// text
	    setText(timeStr,titleStr);
	    addChild(t);
	    
		// frame
		drawFrame();
		addChild(frame);
				
		// events
	    addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
	    addEventListener(MouseEvent.MOUSE_OUT,onMouseOut);
	    addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
	    addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
	}
	
	// テキスト書き換え
	public function setText(timeStr:String, titleStr:String):void {
		var htmlStr:String = '<span class="time">'+timeStr+'</span> <span class="title">'+titleStr+'</span>';
		var style:StyleSheet = new StyleSheet();
		var fontSize:String = '16px';
		style.setStyle('.time',{color:'#fa538b',fontFamily:'GothicBBBPro-Medium',fontSize:fontSize});
		style.setStyle('.title',{color:'#232323',fontFamily:'ShinGoPro-Regular', fontSize:fontSize});
		
		t.autoSize = TextFieldAutoSize.LEFT;
		t.background = true;
		t.backgroundColor = 0xffffff;
		t.selectable = false;
 		t.antiAliasType = flash.text.AntiAliasType.ADVANCED;
		t.styleSheet = style;// スタイルシートが先!
		t.htmlText = htmlStr;// html文字列はあとで入れる! 
	}
	
	// フレームをかく。
	private function drawFrame():void {
		with(frame.graphics){
			lineStyle(1.8,0xfa538b);
			beginFill(0xffffff,0);
			drawRoundRect(-18,-1,t.width+23,t.height ,10,10);
		}
		frame.alpha = 0;
		
		// tiny rect
		var i:Number;
		var ii:Number;
		for(i=0;i<4;i++){
			for(ii=0;ii<5;ii++){
				drawTinyRect(i*3, ii*3);
			}
		}
	}
	private function drawTinyRect(tx:Number,ty:Number):void{
		var tr:Sprite = new Sprite();
		with(tr.graphics){
			beginFill(0xfa538b,0.7);
			drawRect(-14,5.5,2,2);
		}
		tr.x = tx; tr.y = ty;
		frame.addChild(tr);
	}
	
	// 楕円
	private function drawE():void {
		with(de.graphics){
			beginFill(0xff0000);
			drawEllipse(0,0,frame.width,frame.height*2);
		}
		de.x = -18;
		de.y -= frame.height/2;
		trace('yeah')
	}
	
	// 線を引き直す。
	public function drawBorder(tx:Number, ty:Number):void {
		with(bdr.graphics){
			clear();
			lineStyle(2,0xcccccc);
			moveTo(width/2, height/2);
			lineTo(tx-x, ty-y);
		}
	}
	
	
	// イベントハンドラ
	private function onMouseOver(e:MouseEvent):void {
		Tweener.removeTweens(frame);
		Tweener.addTween(frame, { time: 0.5, alpha: 0.7, transition:"linear" } );
	}
	private function onMouseOut(e:MouseEvent):void {
		Tweener.removeTweens(frame);
		Tweener.addTween(frame, { time: 0.5, alpha: 0, transition:"linear" } );
	}
	private function onMouseDown(e:MouseEvent):void {startDrag();}
	private function onMouseUp(e:MouseEvent):void {
		this.stopDrag();
	}
}























/////  WONDERFL TRACE /////

import flash.display.Sprite;
import flash.display.Stage;
import flash.text.TextField;
import flash.text.TextFormat;


function inittrace(s:Stage):void
{
    WTrace.initTrace(s);
}

//global trace function
var trace:Function;

//wtreace class
class WTrace
{
        private static var FONT:String = "Fixedsys";
        private static var SIZE:Number = 12;
        private static var TextFields:Array = [];
        private static var trace_stage:Stage;
        
        public static function initTrace(stg:Stage):void
        {
            trace_stage = stg;
            trace = wtrace;
        }
        
        private static function scrollup():void
        {
            // maximum number of lines: 100
            if (TextFields.length > 100) 
            {
                var removeme:TextField = TextFields.shift();
                trace_stage.removeChild(removeme);
                removeme = null;
            }
            for(var x:Number=0;x<TextFields.length;x++)
            {
                (TextFields[x] as TextField).y -= SIZE*1.2;
            }
        }
    
        public static function wtrace(... args):void
        {
        
            var s:String="";
            var tracefield:TextField;
            
            for (var i:int;i < args.length;i++)
            {
                // imitating flash:
                // putting a space between the parameters
                if (i != 0) s+=" ";
                s+=args[i].toString();
            }
            

            tracefield= new TextField();
            tracefield.autoSize = "left";
            tracefield.text = s;
            tracefield.y = trace_stage.stageHeight - 20;

            var tf:TextFormat = new TextFormat(FONT, SIZE);
            tracefield.setTextFormat(tf);
            trace_stage.addChild(tracefield);
            scrollup();                      
            TextFields.push(tracefield);
            
        }
}