とりあえずWonderfl API を使ってみる
とりあえずWonderfl API を使ってみるテスト
TextAreaはzahirさんの物をお借りしました
http://wonderfl.net/code/3dbe63a794cc621cfbd8d1902cbf2a708dd4dede
/**
* Copyright ton ( http://wonderfl.net/user/ton )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/pgO6
*/
/*
とりあえずWonderfl API を使ってみるテスト
TextAreaはzahirさんの物をお借りしました
http://wonderfl.net/code/3dbe63a794cc621cfbd8d1902cbf2a708dd4dede
*/
package {
import com.adobe.serialization.json.JSON;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TextEvent;
import flash.net.navigateToURL;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.StyleSheet;
import flash.text.TextField;
import flash.text.TextFormat;
public class Main extends Sprite {
private const KEY:String = loaderInfo.parameters.open_api_key;
private const BASE_URL:String = "http://api.wonderfl.net";
private var userName:String = "ton";
private var tf:TextField;
public function Main():void {
tf = new TextField();
tf.defaultTextFormat = new TextFormat("helvetica,arial,clean,sans-serif", 12);
tf.wordWrap = true;
tf.width = 365;
tf.height = 150;
addChild(tf);
var loader1:URLLoader = new URLLoader();
loader1.addEventListener(Event.COMPLETE, onComplete1);
loader1.load(new URLRequest(BASE_URL + "/user/" + userName + "?api_key=" + KEY));
var loader2:URLLoader = new URLLoader();
loader2.addEventListener(Event.COMPLETE, onComplete2);
loader2.load(new URLRequest(BASE_URL + "/user/" + userName + "/codes?api_key=" + KEY));
}
private function linkClick(e:TextEvent):void {
navigateToURL(new URLRequest(e.text));
}
private function onComplete1(e:Event):void {
var user:Object = JSON.decode(e.target.data).user;
tf.htmlText = "<body><a href='event:http://wonderfl.net/user/"+userName+"'><img width='100' height='100' src='"+user.icon+"'></img></a>"
+"<font size='24' color='#EA594F'><b>" + user.name + "</b></font>\n"
+ "<br>URL : <a href='event:" + user.external_url + "'><u>" + user.external_url +"</u></a>\n"
+ user.description.replace(/\r/g, "") + "</body>";
tf.addEventListener(TextEvent.LINK, linkClick);
}
private function onComplete2(e:Event):void {
var codes:Array = JSON.decode(e.target.data).codes;
var ctf:TextArea = new TextArea(465, 335, true, true, false, false, false);
ctf.addEventListener(TextEvent.LINK, linkClick);
ctf.multiline = true;
ctf.wordWrap = true;
ctf.y = 130;
addChild(ctf);
for (var i:int = 0; i < codes.length; i++) {
ctf.htmlText += "<a href='event:http://wonderfl.net/code/" + codes[i].id + "'><img width='100' height='100' src='" + codes[i].thumbnail + "'/></a>"
ctf.htmlText += "<a href='event:http://wonderfl.net/code/" + codes[i].id + "'><font size='14'><b><u>"+codes[i].title + "</u></b></font></a>\n"
var date:Date = new Date(int(codes[i].created_date)*1000);
ctf.htmlText += "created : "+date.fullYear + "/" + (date.month + 1) + "/" + date.date + " " + date.toLocaleTimeString() + "\n";
ctf.htmlText += "license : "+codes[i].license+"\n\n\n\n\n\n";
}
}
}
}
/*
以下zahirさんのTextArea
http://wonderfl.net/code/3dbe63a794cc621cfbd8d1902cbf2a708dd4dede
*/
import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.FocusEvent;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.events.TextEvent;
import flash.filters.ColorMatrixFilter;
import flash.geom.Rectangle;
import flash.text.StyleSheet;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.text.TextLineMetrics;
class TextArea extends Sprite{
public const SCROLL_BAR_WIDTH : int = 16;
private var t:TextField;
// HScrollBar
private var hSliderBg:Sprite;
private var hSlider:HSlider;
// VScrollBar
private var upBtn:UpButton;
private var downBtn:DownButton;
private var vSliderBg:Sprite;
private var vSlider:VSlider;
// up, down, over
private var _arrowColor:Array = [0x999999, 0x333333, 0x666666];
private var _baseColor:Array = [0xEEEEEE, 0xCCCCCC, 0xCCCCCC];
private var _lineColor:Array = [0x999999, 0x0099FF, 0x666666];
private var _barBackgroundColor:uint = 0xCCCCCC;
private var _bg:uint = 0xffffff;
private var _border:uint = 0x333333;
private var _focusBg:uint = 0xFFFFCC;
private var _focusBorder:uint = 0x0099FF;
private var _textColor:uint = 0x000000;
private var _selectTextColor:uint = 0xFFFFFF;
private var _selectBackgroundColor:uint = 0x0099FF;
private var _useHScrollBar:Boolean;
private var _useVScrollBar:Boolean;
private var _useFilter:Boolean;
private var _edit:Boolean;
private var _focus:Boolean;
private var _inFocus:Boolean = false;
private var _draw:Boolean = true;
private var _drag_flg:Boolean = false;
private var hScroll_flg:Boolean = false;
private var vScroll_flg:Boolean = false;
private var w:int, h:int;
private var hScrollThickness:Number;
private var vScrollThickness:Number;
private var clickPoint:int;
private var minHScrollX:int;
private var maxHScrollX:int;
private var minVScrollY:int;
private var maxVScrollY:int;
private var _delayFrame:int = 8;
private var count:int = 0;
public function TextArea( width:int, height:int,
useHScrollBar:Boolean, useVScrollBar:Boolean,
focus:Boolean = false,
useFilter:Boolean = false, editable:Boolean = true){
t = new TextField();
addChild( t );
w = t.width = width;
h = t.height = height;
t.x = t.y = 0;
_useHScrollBar = useHScrollBar;
_useVScrollBar = useVScrollBar;
_useFilter = useFilter;
this.focus = focus;
this.editable = editable;
this.multiline = true;
init();
}
private function init():void{
t.type = (_edit == true) ? TextFieldType.INPUT : TextFieldType.DYNAMIC;
setFilter();
draw();
t.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
t.addEventListener( Event.CHANGE, onChange );
t.addEventListener(Event.SCROLL, onScroll);
t.addEventListener( TextEvent.LINK, onLink );
}
private function addHScrollUI():void{
if(hScroll_flg){
updataHScrollUI();
return;
}
t.height -= SCROLL_BAR_WIDTH;
hSliderBg = new Sprite();
addChild( hSliderBg );
drawH();
var _w:int = hSliderBg.width * (t.width / t.textWidth);
_w = _w < 12 ? 12 : _w;
hSlider = new HSlider( _w, SCROLL_BAR_WIDTH, _arrowColor, _baseColor, _lineColor );
addChild(hSlider);
hSliderBg.addEventListener( MouseEvent.MOUSE_DOWN, onHSliderBgDown);
hSlider.addEventListener( MouseEvent.MOUSE_DOWN, onHSliderDown);
hSlider.cacheAsBitmap = true;
if(useVScrollBar && vScroll_flg)
updataVScrollUI();
updataHScrollUI();
hScroll_flg = true;
_draw = true;
}
private function addVScrollUI():void{
if(vScroll_flg){
updataVScrollUI();
return;
}
t.width -= SCROLL_BAR_WIDTH;
vSliderBg = new Sprite();
addChild(vSliderBg);
upBtn = new UpButton( SCROLL_BAR_WIDTH, _arrowColor, _baseColor, _lineColor);
addChild( upBtn );
downBtn = new DownButton( SCROLL_BAR_WIDTH, _arrowColor, _baseColor, _lineColor);
addChild( downBtn );
var _h:int = (h - SCROLL_BAR_WIDTH*2) * (t.height / t.textHeight);
_h = _h < 12 ? 12 : _h;
vSlider = new VSlider( _h , SCROLL_BAR_WIDTH, _arrowColor, _baseColor, _lineColor);
addChild( vSlider );
drawV();
upBtn.addEventListener( MouseEvent.MOUSE_DOWN, onUpDown );
downBtn.addEventListener( MouseEvent.MOUSE_DOWN, onDownDown );
vSliderBg.addEventListener( MouseEvent.MOUSE_DOWN, onVSliderBgDown );
vSlider.addEventListener( MouseEvent.MOUSE_DOWN, onVSliderDown );
vSlider.cacheAsBitmap = true;
if(useHScrollBar && hScroll_flg)
updataHScrollUI();
updataVScrollUI();
vScroll_flg = true;
_draw = true;
}
private function removeHScrollUI():void{
if( hSliderBg != null && this.contains( hSliderBg) ){
hSliderBg.removeEventListener( MouseEvent.MOUSE_DOWN, onHSliderBgDown);
removeChild(hSliderBg);
}
if( hSlider != null && this.contains( hSlider) ){
hSlider.removeEventListener( MouseEvent.MOUSE_DOWN, onHSliderDown);
removeChild(hSlider);
}
t.height = h;
hScroll_flg = false;
}
private function removeVScrollUI():void{
if( upBtn != null && this.contains(upBtn) ){
upBtn.removeEventListener( MouseEvent.MOUSE_DOWN, onUpDown );
removeChild( upBtn );
}
if( downBtn != null && this.contains(downBtn) ){
downBtn.removeEventListener( MouseEvent.MOUSE_DOWN, onDownDown );
removeChild( downBtn );
}
if( vSliderBg != null && this.contains(vSliderBg) ){
vSliderBg.removeEventListener( MouseEvent.CLICK, onVSliderBgDown);
removeChild( vSliderBg );
}
if( vSlider != null && this.contains(vSlider) ){
vSlider.removeEventListener( MouseEvent.MOUSE_DOWN, onVSliderDown );
removeChild( vSlider );
}
t.width = w;
vScroll_flg = false;
}
private function updataHScrollUI():void{
hSliderBg.y = hSlider.y = t.height;
var _w:int = hSliderBg.width * ( (maxScrollH / 3) / maxScrollH);
hSlider.sliderWidth = _w = _w < 12 ? 12 : _w;
minHScrollX = 0;
maxHScrollX = t.width - hSlider.width;
hScrollThickness = (maxHScrollX - minHScrollX) / ( t.maxScrollH);
hSlider.x = minHScrollX + hScrollThickness * ( t.scrollH);
draw();
}
private function updataVScrollUI():void{
vSliderBg.x = upBtn.x = downBtn.x = vSlider.x = t.width;
downBtn.y = h - SCROLL_BAR_WIDTH - 1;
var _h:int = ( t.height - SCROLL_BAR_WIDTH*2) * (t.height / t.textHeight);
vSlider.sliderHeight = _h < 12 ? 12 : _h;
minVScrollY = upBtn.y + upBtn.height;
maxVScrollY = downBtn.y - vSlider.height;
vScrollThickness = (maxVScrollY - minVScrollY ) / (t.maxScrollV);
vSlider.y = minVScrollY + vScrollThickness * (scrollV - 1);
draw();
}
private function checkUseScrollBar():void{
if( !useHScrollBar && !useVScrollBar ) return;
if( useHScrollBar ){
if( maxScrollH >= 1){
addHScrollUI();
}else if( maxScrollH == 0){
removeHScrollUI();
}
}
if( useVScrollBar ){
if( maxScrollV > 1){
addVScrollUI();
}else if( maxScrollV == 1){
removeVScrollUI();
}
}
}
private function draw():void{
if(!_draw) return;
var g:Graphics = this.graphics;
g.clear();
g.lineStyle( _inFocus ? 2 : 1, _inFocus ? focusBorderColor : borderColor , _inFocus ? 0.8 : 1);
g.beginFill( _inFocus ? focusBackgroundColor : backgroundColor );
g.drawRect(0,0, width, height -1);
g.endFill();
if( hScroll_flg ) drawH();
if( vScroll_flg ) drawV();
_draw = false;
}
private function drawH():void{
var g:Graphics = hSliderBg.graphics;
g.clear();
g.lineStyle( 1, _lineColor[0]);
g.beginFill( _barBackgroundColor );
g.drawRect( 1,0, t.width - 1, SCROLL_BAR_WIDTH - 2);
g.endFill();
}
private function drawV():void{
var g:Graphics = vSliderBg.graphics;
g.clear();
g.lineStyle( 1, _lineColor[0]);
g.beginFill( _barBackgroundColor );
g.drawRect( 1,1, SCROLL_BAR_WIDTH - 2, h -3);
g.endFill();
}
private function setFilter():void{
//引用元 :: http://labs.hellokeita.com/2008/03/13/textfield-selection-color/
// filterを使用する場合 htmlTextで<font color="#RRGGBB">を利用してもテキストの色は統一されるので注意
if( !_useFilter ) return;
const n:Number = 1/255;
var cf:ColorMatrixFilter = new ColorMatrixFilter();
var c:Array = [];
var r:int, g:int, b:int;
c[0] = _selectBackgroundColor >> 16;
c[1] = _selectBackgroundColor >> 8 &0xFF;
c[2] = _selectBackgroundColor &0xFF;
r = _textColor >>16; g = _textColor >> 8 &0xFF; b = _textColor &0xFF;
c[3] = (r - (255 + c[0])) * n + 1;
c[4] = (g - (255 + c[1])) * n + 1;
c[5] = (b - (255 + c[2])) * n + 1;
r = _selectTextColor >>16; g = _selectTextColor >> 8 &0xFF; b = _selectTextColor &0xFF;
c[6] = (r - (255 + c[0])) * n + 1 - c[3];
c[7] = (g - (255 + c[1])) * n + 1 - c[4];
c[8] = (b - (255 + c[2])) * n + 1 - c[5];
cf.matrix = [c[3], c[6], 0, 0, c[0], c[4], c[7], 0, 0, c[1], c[5], c[8], 0, 0, c[2], 0, 0, 0, 1, 0];
t.textColor = 0xFF0000;
t.filters = [ cf ];
}
public function get backgroundColor():uint{
return _bg;
}
public function set backgroundColor( value:uint ):void{
_bg = value;
_draw = true;
draw()
}
public function get borderColor():uint{
return _border;
}
public function set borderColor( value:uint ):void{
_border = value;
_draw = true;
draw();
}
public function set barBackgroundColor( value:uint ):void{
_barBackgroundColor = value;
_draw = true;
draw();
}
public function get delayFrame():int{
return _delayFrame;
}
public function set delayFrame( value:int ):void{
_delayFrame = value < 0 ? 0:Math.round( value );
}
public function get editable():Boolean{ return _edit; }
public function set editable( flg:Boolean ):void {
_edit = flg;
t.type = (_edit == true) ? TextFieldType.INPUT : TextFieldType.DYNAMIC;
}
public function get filtering():Boolean{ return _useFilter; }
public function set filtering( flg:Boolean ):void{
_useFilter = flg;
if(!flg) t.filters = [];
}
public function get focus():Boolean{ return _focus; }
public function set focus( flg:Boolean ):void{
_focus = flg;
if(flg){
t.addEventListener(FocusEvent.FOCUS_IN, inFocus);
}else{
t.removeEventListener(FocusEvent.FOCUS_IN, inFocus);
}
}
public function get focusBackgroundColor():uint{ return _focusBg; }
public function set focusBackgroundColor( value:uint ):void{ _focusBg = value; }
public function get focusBorderColor():uint{ return _focusBorder; }
public function set focusBorderColor( value:uint ):void{ _focusBorder = value; }
public override function get height():Number{
return Math.floor( super.height );
}
public override function set height( value:Number ):void{
h = Math.round( value );
_draw = true;
if(hScroll_flg){
t.height = h - SCROLL_BAR_WIDTH;
updataHScrollUI();
}else t.height = h;
if(vScroll_flg) updataVScrollUI();
draw();
}
public function get selectBackgroundColor():uint{ return _selectBackgroundColor; }
public function set selectBackgroundColor( value:uint ):void{_selectBackgroundColor = value; setFilter();}
public function get selectTextColor():uint{ return _selectTextColor; }
public function set selectTextColor( value:uint ):void{ _selectTextColor = value; setFilter();}
public function get textColor():uint{ return _textColor; }
public function set textColor(value:uint):void{ _textColor = value; setFilter();}
public function set UIArrowColor( arr:Array ):void{
if(arr.length != 3) return;
_arrowColor = arr;
upBtn.arrowColors = downBtn.arrowColors = vSlider.arrowColors = arr;
}
public function set UIBaseColor( arr:Array ):void{
if(arr.length != 3) return;
_baseColor = arr;
upBtn.baseColors = downBtn.baseColors = vSlider.baseColors = arr;
}
public function set UILineColor( arr:Array ):void{
if(arr.length != 3) return;
_lineColor = arr;
upBtn.lineColors = downBtn.lineColors = vSlider.lineColors = arr;
}
public function get useHScrollBar():Boolean{ return _useHScrollBar; }
public function set useHScrollBar( flg:Boolean ):void{ _useHScrollBar = flg; }
public function get useVScrollBar():Boolean{ return _useVScrollBar; }
public function set useVScrollBar( flg:Boolean ):void{ _useVScrollBar = flg; }
public override function get width():Number{
return Math.floor( super.width );
}
public override function set width(value:Number):void{
w = Math.round( value );
_draw = true;
if(vScroll_flg){
t.width = w - SCROLL_BAR_WIDTH;
updataVScrollUI();
}else t.width = w;
if(hScroll_flg) updataHScrollUI();
draw();
}
// HSliderBg
protected function onHSliderBgDown( e:MouseEvent ):void{
var p:int = mouseX;
p = p < minHScrollX ? minHScrollX : p > maxHScrollX? maxHScrollX : p;
scrollH = p / hScrollThickness + 1;
hSliderBg.stage.addEventListener(MouseEvent.MOUSE_MOVE, onHSliderBgMove);
hSliderBg.stage.addEventListener(MouseEvent.MOUSE_UP, onHSliderBgUp);
}
protected function onHSliderBgMove( e:MouseEvent ):void{
var p:int = mouseX;
p = p < minHScrollX ? minHScrollX : p > maxHScrollX? maxHScrollX : p;
scrollH = p / hScrollThickness + 1;
e.updateAfterEvent();
}
protected function onHSliderBgUp( e:MouseEvent ):void{
hSliderBg.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onHSliderBgMove);
hSliderBg.stage.removeEventListener(MouseEvent.MOUSE_UP, onHSliderBgUp);
}
protected function onHSliderDown( e:MouseEvent ):void{
_drag_flg = true;
clickPoint = hSlider.mouseX;
hSlider.stage.addEventListener( MouseEvent.MOUSE_MOVE, onHSliderMove );
hSlider.stage.addEventListener( MouseEvent.MOUSE_UP, onHSliderUp );
}
protected function onHSliderMove( e:MouseEvent ):void{
var p:int = mouseX - clickPoint;
hSlider.x = p = p < minHScrollX ? minHScrollX : p > maxHScrollX? maxHScrollX : p;
scrollH = p / hScrollThickness + 1;
}
protected function onHSliderUp( e:MouseEvent ):void{
_drag_flg = false;
hSlider.stage.removeEventListener( MouseEvent.MOUSE_MOVE, onHSliderMove );
hSlider.stage.removeEventListener( MouseEvent.MOUSE_UP, onHSliderUp );
}
// VSliderBg
protected function onVSliderBgDown( e:MouseEvent ):void{
var p:int = mouseY;
p = p < minVScrollY ? minVScrollY : p > maxVScrollY? maxVScrollY : p;
scrollV = ( p - SCROLL_BAR_WIDTH ) / vScrollThickness + 1;
vSliderBg.stage.addEventListener(MouseEvent.MOUSE_MOVE, onVSliderBgMove);
vSliderBg.stage.addEventListener(MouseEvent.MOUSE_UP, onVSliderBgUp);
}
protected function onVSliderBgMove( e:MouseEvent ):void{
var p:int = mouseY;
p = p < minVScrollY ? minVScrollY : p > maxVScrollY? maxVScrollY : p;
scrollV = ( p - SCROLL_BAR_WIDTH ) / vScrollThickness + 1;
e.updateAfterEvent();
}
protected function onVSliderBgUp( e:MouseEvent ):void{
vSliderBg.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onVSliderBgMove);
vSliderBg.stage.removeEventListener(MouseEvent.MOUSE_UP, onVSliderBgUp);
}
// VSlider
protected function onVSliderDown( e:MouseEvent ):void{
_drag_flg = true;
clickPoint = vSlider.mouseY;
vSlider.stage.addEventListener( MouseEvent.MOUSE_MOVE, onVSliderMove );
vSlider.stage.addEventListener( MouseEvent.MOUSE_UP, onVSliderUp );
}
protected function onVSliderMove( e:MouseEvent):void{
var p:int = mouseY - clickPoint;
vSlider.y = p = p < minVScrollY ? minVScrollY : p > maxVScrollY? maxVScrollY : p;
scrollV = ( p - SCROLL_BAR_WIDTH ) / vScrollThickness + 1;
e.updateAfterEvent();
}
protected function onVSliderUp( e:MouseEvent ):void{
_drag_flg = false;
vSlider.stage.removeEventListener( MouseEvent.MOUSE_MOVE, onVSliderMove );
vSlider.stage.removeEventListener( MouseEvent.MOUSE_UP, onVSliderUp );
}
// Up Button
protected function onUpDown( e:MouseEvent ):void{
scrollV--;
count = 0;
addEventListener(Event.ENTER_FRAME, onUpFrame);
stage.addEventListener( MouseEvent.MOUSE_UP, onUpUp);
}
protected function onUpUp( e:MouseEvent ):void{
removeEventListener(Event.ENTER_FRAME, onUpFrame);
stage.removeEventListener( MouseEvent.MOUSE_UP, onUpUp);
}
protected function onUpFrame( e:Event ):void{
if( count <= delayFrame){
count ++;
return;
}
scrollV--;
}
// Down Button
protected function onDownDown( e:MouseEvent):void{
scrollV++;
count = 0;
addEventListener(Event.ENTER_FRAME, onDownFrame);
stage.addEventListener( MouseEvent.MOUSE_UP, onDownUp);
}
protected function onDownUp(e:MouseEvent):void{
removeEventListener(Event.ENTER_FRAME, onDownFrame);
stage.removeEventListener( MouseEvent.MOUSE_UP, onDownUp);
}
protected function onDownFrame( e:Event ):void{
if( count <= delayFrame){
count ++;
return;
}
scrollV++;
}
protected function onChange( e:Event ):void{
checkUseScrollBar();
dispatchEvent( e );
}
protected function onScroll( e:Event ):void{
dispatchEvent( e );
if(_drag_flg) return;
if(hScroll_flg)
hSlider.x = scrollH == 1 ? minHScrollX : minHScrollX + hScrollThickness * scrollH;
if(vScroll_flg)
vSlider.y = scrollV == 1 ? minVScrollY : minVScrollY + vScrollThickness * scrollV;
}
protected function inFocus( e:FocusEvent ):void{
_inFocus = true;
_draw = true;
draw();
}
protected function outFocus( e:FocusEvent ):void{
_inFocus = false;
_draw = true;
draw();
}
protected function onLink( e:TextEvent ):void{
dispatchEvent( e );
}
protected function onKeyDown( e:KeyboardEvent ):void{
t.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
}
protected function onKeyUp( e:KeyboardEvent ):void{
t.removeEventListener( KeyboardEvent.KEY_UP, onKeyUp);
}
// TextFieldのプロパティーとかメソッドとか
public function get alwaysShowSelection():Boolean{ return t.alwaysShowSelection; }
public function set alwaysShowSelection(flg:Boolean):void{ t.alwaysShowSelection = flg; }
public function get antiAliasType():String{ return t.antiAliasType; }
public function set antiAliasType(str:String):void{ t.antiAliasType = str; }
public function get bottomScroll():int{ return t.bottomScrollV; }
public function get caretIndex():int{ return t.caretIndex; }
public function get condenseWhite():Boolean{ return t.condenseWhite; }
public function set condenseWhite(flg:Boolean):void{ t.condenseWhite = flg; }
public function get defaultTextFormat():TextFormat{ return t.defaultTextFormat; }
public function set defaultTextFormat(data:TextFormat):void{ t.defaultTextFormat = data; }
public function get embedFonts():Boolean{ return t.embedFonts; }
public function set embedFonts(flg:Boolean):void{ t.embedFonts = flg; }
public function get gridFitType():String{ return t.gridFitType; }
public function set gridFitType(str:String):void{ t.gridFitType = str; }
public function get htmlText():String{ return t.htmlText; }
public function set htmlText(str:String):void{ t.htmlText = str; checkUseScrollBar();}
public function get length():int{ return t.length; }
public function get maxChars():int{ return t.maxChars; }
public function set maxChars(value:int):void{ t.maxChars = value; }
public function get maxScrollH():int{ return t.maxScrollH; }
public function get maxScrollV():int{ return t.maxScrollV; }
public function get mouseWheelEnabled():Boolean{ return t.mouseWheelEnabled; }
public function set mouseWheelEnabled(flg:Boolean):void{ t.mouseWheelEnabled = flg; }
public function get multiline():Boolean{ return t.multiline; }
public function set multiline(flg:Boolean):void{ t.multiline = flg; }
public function get numLines():int{ return t.numLines; }
public function get restrict():String{ return t.restrict; }
public function set restrict(str:String):void{ t.restrict = str; }
public function get scrollH():int{ return t.scrollH; }
public function set scrollH(value:int):void{ t.scrollH = value; }
public function get scrollV():int{ return t.scrollV; }
public function set scrollV(value:int):void{ t.scrollV = value; }
public function get selectable():Boolean{ return t.selectable; }
public function set selectable(flg:Boolean):void{ t.selectable = flg; }
public function get selectedText():String{ return t.selectedText; }
public function get selectionBeginIndex():int{ return t.selectionBeginIndex; }
public function get selectionEndIndex():int{ return t.selectionEndIndex; }
public function get sharpness():Number{ return t.sharpness; }
public function set sharpness(value:Number):void{ t.sharpness = value; }
public function get styleSheet():StyleSheet{ return t.styleSheet; }
public function set styleSheet(data:StyleSheet):void{ t.styleSheet = data; }
public function get text():String{ return t.text; }
public function set text(str:String):void{ t.text = str; checkUseScrollBar();}
public function get textHeight():Number{ return t.textHeight; }
public function get textWidth():Number{ return t.textWidth; }
public function get thickness():Number{ return t.thickness; }
public function set thickness(value:Number):void{ t.thickness = value; }
public function get useRichTextClipboard():Boolean{ return t.useRichTextClipboard; }
public function set useRichTextClipboard(flg:Boolean):void{ t.useRichTextClipboard = flg; }
public function get wordWrap():Boolean{ return t.wordWrap; }
public function set wordWrap(flg:Boolean):void{ t.wordWrap = flg; }
public function appendText(newText:String):void{ t.appendText( newText ); }
public function getCharBoundaries(charIndex:int):Rectangle{ return t.getCharBoundaries( charIndex ); }
public function getCharIndexAtPoint(x:Number, y:Number):int{ return t.getCharIndexAtPoint( x, y ); }
public function getFirstCharInParagraph(charIndex:int):int{ return t.getFirstCharInParagraph( charIndex ); }
public function getImageReference(id:String):DisplayObject{ return t.getImageReference( id ); }
public function getLineIndexAtPoint(x:Number, y:Number):int{ return t.getLineIndexAtPoint( x, y); }
public function getLineIndexOfChar(charIndex:int):int{ return t.getLineIndexOfChar( charIndex ); }
public function getLineLength(lineIndex:int):int{ return t.getLineLength( lineIndex ); }
public function getLineMetrics(lineIndex:int):TextLineMetrics{ return t.getLineMetrics( lineIndex ); }
public function getLineOffset(lineIndex:int):int{ return t.getLineOffset( lineIndex ); }
public function getLineText(lineIndex:int):String{ return t.getLineText( lineIndex ); }
public function getParagraphLength(charIndex:int):int{ return t.getParagraphLength( charIndex ); }
public function getRawText():String{ return t.getRawText(); }
public function getTextFormat(beginIndex:int, endIndex:int):TextFormat{ return t.getTextFormat( beginIndex, endIndex ); }
public function getTextRuns(beginIndex:int=0, endIndex:int=2147483647):Array{ return t.getTextRuns( beginIndex, endIndex ); }
public function getXMLText(beginIndex:int=0, endIndex:int=2147483647):String{ return t.getXMLText( beginIndex, endIndex ); }
public function replaceSelectedText(value:String):void{ t.replaceSelectedText( value ); }
public function replaceText(beginIndex:int, endIndex:int, newText:String):void{ t.replaceText( beginIndex, endIndex, newText ); }
public function setSelection(beginIndex:int, endIndex:int):void{ t.setSelection( beginIndex, endIndex ); }
public function setTextFormat(format:TextFormat, beginIndex:int, endIndex:int):void{ t.setTextFormat( format, beginIndex, endIndex ); }
}
class MyButton extends Sprite{
protected var flg:Boolean = false;
protected var over_flg:Boolean = false;
// up, down, over
protected var _arrowColor:Array ;
protected var _baseColor:Array;
protected var _lineColor:Array;
protected var _thickness:Array = [1,2,1];
protected var _side:int;
protected var ui:Sprite;
public function set arrowColors( arr:Array ):void{
_arrowColor = arr;
draw();
}
public function set baseColors( arr:Array ):void{
_baseColor = arr;
draw();
}
public function set lineColors( arr:Array ):void{
_lineColor = arr;
draw();
}
public function MyButton( side:int, arrowColor:Array, baseColor:Array, lineColor:Array ){
_side = side;
_arrowColor = arrowColor;
_baseColor = baseColor;
_lineColor = lineColor;
ui = new Sprite();
addChild( ui );
var g:Graphics = this.graphics;
g.beginFill( _baseColor[ 0 ], 0.02);
g.drawRect( 0,0, side,side);
g.endFill();
draw();
addEventListener( MouseEvent.MOUSE_DOWN, onDown );
addEventListener( MouseEvent.MOUSE_OVER, onOver );
}
protected function draw( num:int = 0 ):void{
if( num >= 3) return;
// overrideして描画処理しよう
}
protected function onDown( e:MouseEvent ):void{
flg = true;
draw( 1 );
stage.addEventListener( MouseEvent.MOUSE_UP, onUp );
}
protected function onUp( e:MouseEvent ):void{
flg = false;
over_flg == true ? draw(2): draw();
stage.removeEventListener( MouseEvent.MOUSE_UP, onUp );
}
protected function onOver( e:MouseEvent ):void{
over_flg = true;
if(flg) return;
draw( 2 );
addEventListener( MouseEvent.MOUSE_OUT, onOut );
}
protected function onOut( e:MouseEvent ):void{
over_flg = false;
if(flg) return;
draw();
removeEventListener( MouseEvent.MOUSE_OUT, onOut );
}
}
class HSlider extends MyButton{
private var _width:int;
public function HSlider( width:int, side:int, arrowColor:Array, baseColor:Array, lineColor:Array ){
_width = width;
super( side, arrowColor, baseColor, lineColor );
}
public function set sliderWidth( value:int ):void{
_width = value;
draw();
}
protected override function draw( num:int = 0):void{
super.draw( num );
var g:Graphics = ui.graphics;
g.clear();
g.lineStyle( 1, _lineColor[ num ]);
g.beginFill( _baseColor[ num ] );
g.drawRect( 2,1, _width, _side - 4);
g.endFill();
var ww:int = _width >>1;
var t:int = _side >>1;
var b:int = t;
t -= 4;
b +=4;
g.lineStyle( 1, _arrowColor[ num ]);
g.moveTo( ww -3, t);
g.lineTo( ww - 3, b);
g.moveTo( ww, t);
g.lineTo( ww, b);
g.moveTo( ww +3, t);
g.lineTo( ww + 3, b);
}
}
class VSlider extends MyButton{
private var _height:int;
public function VSlider( height:int, side:int, arrowColor:Array, baseColor:Array, lineColor:Array ){
_height = height;
super( side, arrowColor, baseColor, lineColor );
}
public function set sliderHeight( value:int ):void{
_height = value;
draw();
}
protected override function draw( num:int = 0):void{
super.draw( num );
var g:Graphics = ui.graphics;
g.clear();
g.lineStyle( 1, _lineColor[ num ]);
g.beginFill( _baseColor[ num ] );
g.drawRect( 2,1, _side - 4, _height);
g.endFill();
var hh:int = _height >>1;
var l:int = _side >>1;
var r:int = l;
l -= 4;
r +=4;
g.lineStyle( 1, _arrowColor[ num ]);
g.moveTo( l, hh - 3);
g.lineTo( r, hh - 3);
g.moveTo( l, hh);
g.lineTo( r, hh);
g.moveTo( l, hh + 3);
g.lineTo( r, hh + 3);
}
}
class UpButton extends MyButton{
public function UpButton( side:int, arrowColor:Array, baseColor:Array, lineColor:Array ){
super( side, arrowColor, baseColor, lineColor );
}
protected override function draw( num:int = 0):void{
super.draw( num );
var g:Graphics = ui.graphics;
var l:int =_thickness[ num ];
g.clear();
g.lineStyle( l, _lineColor[ num ]);
g.beginFill( _baseColor[ num ] );
g.drawRect( l,l, _side - (l+1),_side - (l+1));
g.endFill();
g.lineStyle( 0, 0, 0);
g.beginFill( _arrowColor[ num ]);
g.moveTo( 5, _side - 5);
g.lineTo( _side - 5, _side -5);
g.lineTo( _side/2, 6);
g.lineTo( 5, _side -5);
g.endFill();
}
}
class DownButton extends MyButton{
public function DownButton( side:int, arrowColor:Array, baseColor:Array, lineColor:Array ){
super( side, arrowColor, baseColor, lineColor );
}
protected override function draw( num:int = 0):void{
super.draw( num );
var g:Graphics = ui.graphics;
var l:int =_thickness[ num ];
g.clear();
g.lineStyle( l, _lineColor[ num ]);
g.beginFill( _baseColor[ num ] );
g.drawRect( l,l, _side - (l+1),_side - (l+1));
g.endFill();
g.lineStyle( 0, 0, 0);
g.beginFill( _arrowColor[ num ]);
g.moveTo( 5, 7);
g.lineTo( _side - 5, 7);
g.lineTo( _side/2, _side - 5);
g.lineTo( 5, 7);
g.endFill();
}
}