| 1 |
package { |
|---|
| 2 |
// 必要なパッケージの読み込み. |
|---|
| 3 |
import flash.geom.*; |
|---|
| 4 |
import flash.display.Sprite; |
|---|
| 5 |
import flash.display.GradientType; |
|---|
| 6 |
import flash.display.SpreadMethod; |
|---|
| 7 |
|
|---|
| 8 |
[IconFile("Line_icon.png")] |
|---|
| 9 |
public class Line extends Sprite{ |
|---|
| 10 |
|
|---|
| 11 |
public var __w :Number = 100; |
|---|
| 12 |
public var __h :Number = 4; |
|---|
| 13 |
public var __color :uint = 0x000000; |
|---|
| 14 |
public var __alpha :Number = 1; |
|---|
| 15 |
public var __lineType :String = "実線"; |
|---|
| 16 |
public var __breakLineWidth :Number = 8; |
|---|
| 17 |
public var __breakLineMargin:Number = 4; |
|---|
| 18 |
|
|---|
| 19 |
public var mask_spr:Sprite; |
|---|
| 20 |
public var body_spr:Sprite; |
|---|
| 21 |
|
|---|
| 22 |
public function Line(){ |
|---|
| 23 |
var _vw:Number = 0; |
|---|
| 24 |
var _vh:Number = 0; |
|---|
| 25 |
//ASのnewで生成されたかタイムライン上の配置で生成されたかを判別する |
|---|
| 26 |
if(this.parent == null){ |
|---|
| 27 |
//親がnull = まだaddChildされてない = newで生成された |
|---|
| 28 |
_vw = __w; |
|---|
| 29 |
_vh = __h; |
|---|
| 30 |
}else{ |
|---|
| 31 |
//親がnull以外 = コンストラクタ前の時点でaddChildされてる = タイムラインで生成された |
|---|
| 32 |
_vw = (super.width == 0) ? __w:super.width; |
|---|
| 33 |
_vh = (super.height == 0) ? __h:super.height; |
|---|
| 34 |
scaleX = 1;//scaleは1に戻しておく |
|---|
| 35 |
scaleY = 1;//scaleは1に戻しておく |
|---|
| 36 |
//初回のサイズ取得に使った透明塗りの大きさを0にしたあと消してしまう |
|---|
| 37 |
var tmp_Shape:* = getChildAt(0); |
|---|
| 38 |
tmp_Shape.width = 0; |
|---|
| 39 |
tmp_Shape.height = 0; |
|---|
| 40 |
tmp_Shape.visible = false; |
|---|
| 41 |
removeChild(tmp_Shape); |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
//描画用sprとマスク用sprを生成 |
|---|
| 45 |
mask_spr = new Sprite(); |
|---|
| 46 |
body_spr = new Sprite(); |
|---|
| 47 |
addChild(mask_spr); |
|---|
| 48 |
addChild(body_spr); |
|---|
| 49 |
//マスクを実装 |
|---|
| 50 |
this.body_spr.mask = this.mask_spr; |
|---|
| 51 |
|
|---|
| 52 |
//whを取得したのちscale値を元に戻す |
|---|
| 53 |
this.__w = _vw; |
|---|
| 54 |
this.__h = _vh; |
|---|
| 55 |
this.alpha = __alpha; |
|---|
| 56 |
|
|---|
| 57 |
this.width = __w; |
|---|
| 58 |
this.height = __h; |
|---|
| 59 |
this.color = __color; |
|---|
| 60 |
this.breakLineWidth = __breakLineWidth; |
|---|
| 61 |
this.breakLineMargin = __breakLineMargin; |
|---|
| 62 |
this.lineType = __lineType; |
|---|
| 63 |
} |
|---|
| 64 |
// -------------------------------------------------------------------// |
|---|
| 65 |
// setter |
|---|
| 66 |
// -------------------------------------------------------------------// |
|---|
| 67 |
public override function set width(_num:Number):void{ |
|---|
| 68 |
__w = _num; |
|---|
| 69 |
updateShape(); |
|---|
| 70 |
} |
|---|
| 71 |
// -------------------------------------------------------------------// |
|---|
| 72 |
public override function set height(_num:Number):void{ |
|---|
| 73 |
__h = _num; |
|---|
| 74 |
updateShape(); |
|---|
| 75 |
} |
|---|
| 76 |
// -------------------------------------------------------------------// |
|---|
| 77 |
public override function set alpha(_num:Number):void{ |
|---|
| 78 |
__alpha = _num; |
|---|
| 79 |
updateShape(); |
|---|
| 80 |
} |
|---|
| 81 |
// -------------------------------------------------------------------// |
|---|
| 82 |
[Inspectable(defaultValue="#000000", name="01.色", type="Color")] |
|---|
| 83 |
public function set color(_num:uint):void{ |
|---|
| 84 |
__color = _num; |
|---|
| 85 |
updateShape(); |
|---|
| 86 |
} |
|---|
| 87 |
// -------------------------------------------------------------------// |
|---|
| 88 |
[Inspectable(defaultValue=8, name="02.破線の横幅", type="Number")] |
|---|
| 89 |
public function set breakLineWidth(_num:Number):void{ |
|---|
| 90 |
__breakLineWidth = _num; |
|---|
| 91 |
updateShape(); |
|---|
| 92 |
} |
|---|
| 93 |
// -------------------------------------------------------------------// |
|---|
| 94 |
[Inspectable(defaultValue=4, name="03.破線の余白", type="Number")] |
|---|
| 95 |
public function set breakLineMargin(_num:Number):void{ |
|---|
| 96 |
__breakLineMargin = _num; |
|---|
| 97 |
updateShape(); |
|---|
| 98 |
} |
|---|
| 99 |
// -------------------------------------------------------------------// |
|---|
| 100 |
[Inspectable(defaultValue="実線", name="04.線の種類", type="List", enumeration="実線,破線,点線,続く線,続き線")] |
|---|
| 101 |
public function set lineType(_str:String):void{ |
|---|
| 102 |
__lineType = _str; |
|---|
| 103 |
updateShape(); |
|---|
| 104 |
} |
|---|
| 105 |
// -------------------------------------------------------------------// |
|---|
| 106 |
// getter |
|---|
| 107 |
// -------------------------------------------------------------------// |
|---|
| 108 |
public override function get width():Number{ |
|---|
| 109 |
return __w; |
|---|
| 110 |
} |
|---|
| 111 |
// -------------------------------------------------------------------// |
|---|
| 112 |
public override function get height():Number{ |
|---|
| 113 |
return __h; |
|---|
| 114 |
} |
|---|
| 115 |
// -------------------------------------------------------------------// |
|---|
| 116 |
public function get color():uint{ |
|---|
| 117 |
return __color; |
|---|
| 118 |
} |
|---|
| 119 |
// -------------------------------------------------------------------// |
|---|
| 120 |
public function get lineType():String{ |
|---|
| 121 |
return __lineType; |
|---|
| 122 |
} |
|---|
| 123 |
// -------------------------------------------------------------------// |
|---|
| 124 |
// public Function |
|---|
| 125 |
// -------------------------------------------------------------------// |
|---|
| 126 |
public function setSize(w:Number,h:Number){ |
|---|
| 127 |
width = w; |
|---|
| 128 |
height = h; |
|---|
| 129 |
} |
|---|
| 130 |
// -------------------------------------------------------------------// |
|---|
| 131 |
// private Function |
|---|
| 132 |
// -------------------------------------------------------------------// |
|---|
| 133 |
private function updateShape(){ |
|---|
| 134 |
body_spr.graphics.clear(); |
|---|
| 135 |
|
|---|
| 136 |
var _color:uint = __color; |
|---|
| 137 |
var _alpha:uint = __alpha; |
|---|
| 138 |
|
|---|
| 139 |
var i = 0; |
|---|
| 140 |
var c = 0; |
|---|
| 141 |
var tx = 0; |
|---|
| 142 |
var tw = 0; |
|---|
| 143 |
var vm = 0; |
|---|
| 144 |
switch(__lineType){ |
|---|
| 145 |
case "実線": |
|---|
| 146 |
drawShape(0,0,__w,__h); |
|---|
| 147 |
break; |
|---|
| 148 |
case "破線": |
|---|
| 149 |
c = Math.ceil(__w / (__breakLineWidth+__breakLineMargin)); |
|---|
| 150 |
for(i = 0;i < c;i++){ |
|---|
| 151 |
tx = (__breakLineWidth+__breakLineMargin) * i; |
|---|
| 152 |
drawShape(tx,0,__breakLineWidth,__h); |
|---|
| 153 |
} |
|---|
| 154 |
break; |
|---|
| 155 |
case "点線": |
|---|
| 156 |
c = Math.ceil(__w / (__h+__breakLineMargin)); |
|---|
| 157 |
for(i = 0;i < c;i++){ |
|---|
| 158 |
tx = (__h+__breakLineMargin) * i; |
|---|
| 159 |
drawCircle(tx+(__h/2),__h/2,__h/2); |
|---|
| 160 |
} |
|---|
| 161 |
break; |
|---|
| 162 |
case "続く線": |
|---|
| 163 |
tw = __w - ((__breakLineWidth+__breakLineMargin)*2); |
|---|
| 164 |
drawShape(0,0,tw,__h); |
|---|
| 165 |
drawShape(tw+__breakLineMargin,0,__breakLineWidth,__h); |
|---|
| 166 |
drawShape(tw+(__breakLineWidth+__breakLineMargin*2),0,__breakLineWidth,__h); |
|---|
| 167 |
break; |
|---|
| 168 |
case "続き線": |
|---|
| 169 |
tw = __w - ((__breakLineWidth+__breakLineMargin)*2); |
|---|
| 170 |
drawShape(0,0,__breakLineWidth,__h); |
|---|
| 171 |
drawShape(__breakLineWidth+__breakLineMargin,0,__breakLineWidth,__h); |
|---|
| 172 |
drawShape((__breakLineWidth+__breakLineMargin)*2,0,tw,__h); |
|---|
| 173 |
break; |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
//マスクを更新 |
|---|
| 177 |
updateMask(); |
|---|
| 178 |
} |
|---|
| 179 |
// -------------------------------------------------------------------// |
|---|
| 180 |
//四角形を描く |
|---|
| 181 |
private function drawShape(vx,vy,vw,vh){ |
|---|
| 182 |
var fillType = GradientType.LINEAR; |
|---|
| 183 |
var colors = [__color,__color]; |
|---|
| 184 |
var alphas = [__alpha,__alpha]; |
|---|
| 185 |
var ratios = [0,255]; |
|---|
| 186 |
body_spr.graphics.beginGradientFill(fillType, colors, alphas, ratios); |
|---|
| 187 |
body_spr.graphics.drawRect (vx,vy,vw,vh); |
|---|
| 188 |
body_spr.graphics.endFill(); |
|---|
| 189 |
} |
|---|
| 190 |
// -------------------------------------------------------------------// |
|---|
| 191 |
//丸を描く |
|---|
| 192 |
private function drawCircle(vx,vy,vwh){ |
|---|
| 193 |
var fillType = GradientType.LINEAR; |
|---|
| 194 |
var colors = [__color,__color]; |
|---|
| 195 |
var alphas = [__alpha,__alpha]; |
|---|
| 196 |
var ratios = [0,255]; |
|---|
| 197 |
body_spr.graphics.beginGradientFill(fillType, colors, alphas, ratios); |
|---|
| 198 |
body_spr.graphics.drawCircle (vx,vy,vwh); |
|---|
| 199 |
body_spr.graphics.endFill(); |
|---|
| 200 |
} |
|---|
| 201 |
// -------------------------------------------------------------------// |
|---|
| 202 |
//マスク領域を再描画 |
|---|
| 203 |
private function updateMask(){ |
|---|
| 204 |
mask_spr.graphics.clear(); |
|---|
| 205 |
var fillType = GradientType.LINEAR; |
|---|
| 206 |
var colors = [0xFFFFFF,0xFFFFFF]; |
|---|
| 207 |
var alphas = [1,1]; |
|---|
| 208 |
var ratios = [0,255]; |
|---|
| 209 |
mask_spr.graphics.beginGradientFill(fillType, colors, alphas, ratios); |
|---|
| 210 |
mask_spr.graphics.drawRect (0,0,__w,__h); |
|---|
| 211 |
mask_spr.graphics.endFill(); |
|---|
| 212 |
} |
|---|
| 213 |
} |
|---|
| 214 |
} |
|---|