forked from: flash on 2014-6-4
forked from flash on 2014-6-4 (diff: 223)
プレイヤー画面の作成 画面構成 シークバー追加 ボタン類追加
ActionScript3 source code
/**
* Copyright tepe ( http://wonderfl.net/user/tepe )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/jRGQ
*/
package{
import flash.display.*;
import flash.text.*;
import flash.events.*;
public class Main extends Sprite{
public function Main(){
var player:TubePlayer2 = new TubePlayer2();
addChild(player);
}
}
}
// forked from tepe's flash on 2014-6-4
//プレイヤー画面の作成
//画面構成
//シークバー追加
//ボタン類追加
//package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.ui.*;
class TubePlayer2 extends Sprite {
private var loader:TubeLoader;
private var player:TubePlayer= new TubePlayer();
private var seekBar:Slider;
private var playList:Array = new Array();
private var debug:TextField = new TextField();
public function TubePlayer2() {
// write as3 code here..
debug.text = "debug\n";
addChild(debug);
debug.x = 330;
debug.width= 300;
loader = new TubeLoader();
player.addEventListener(MouseEvent.MOUSE_OVER,rollOver);
player.addEventListener(MouseEvent.MOUSE_OUT,rollOut);
addChild(player);
var sb:SeekBar = new SeekBar();
addChild(sb);
sb.y = 240;
sb.setSize(320,10);
sb.length = 10000;
sb.x = 0;
sb.setColor(0x44aaff,0x333333);
sb.addEventListener(CompoEvent.CHANGE, function():void{
player.seek = sb.value;
debug.appendText(sb.value.toString()+"\n");
debug.scrollV = debug.maxScrollV;
});
sb.addEventListener(Event.ENTER_FRAME, function():void{
if(player.end!=sb.length)sb.length = player.end;
sb.value = player.seek;
});
}
private function rollOver(e:MouseEvent):void{
debug.appendText("onRollOver\n");
debug.scrollV = debug.maxScrollV;
Mouse.cursor = MouseCursor.BUTTON;
}
private function rollOut(e:MouseEvent):void{
debug.appendText("out\n");
debug.scrollV = debug.maxScrollV;
Mouse.cursor = MouseCursor.AUTO;
}
private function play(e:MouseEvent=null):void {
player.play("rmYU2ikxjpA");
seekBar.addEventListener(Event.ENTER_FRAME,onFrame);
}
private function pause(e:MouseEvent=null):void {
player.pause();
seekBar.removeEventListener(Event.ENTER_FRAME,onFrame);
}
private function onFrame(e:Event=null):void{
seekBar.max = player.end;
seekBar.value = player.seek;
}
private function onSeek(e:CompoEvent):void {
player.seek = seekBar.value;
}
}
//}
import flash.text.*;
import flash.display.*;
import flash.net.*;
import flash.events.*;
import flash.utils.*;
import flash.system.*;
class TubeLoader extends Sprite{
//動画ID取得
//投稿者取得
//動画タイトル取得
//再生時間取得
//キーワード検索
//投稿者検索
private var loader:URLLoader;
public var idList:Array;
public var titleList:Array;
public var authorList:Array;
public var durationList:Array;
private var _words:String = "";//前回の検索ワード
private var cnt:int=0;//リクエスト回数
private var _results:int = 20;
public function TubeLoader() {
idList = new Array();
titleList = new Array();
authorList = new Array();
durationList = new Array();
}
public function clear():void{
idList = new Array();
titleList = new Array();
authorList = new Array();
durationList = new Array();
cnt=0;
}
public function set results(n:int):void{
_results = n;
clear();
}
//キーワード検索
public function requestWords(key:String):void{
//var str:String = "http://gdata.youtube.com/feeds/api/videos/-/";
var str:String = "http://gdata.youtube.com/feeds/api/videos?"
if(_words != key){
_words = key;
clear();
}
str += "q="+escapeMultiByte(_words);//検索ワード
//str += escapeMultiByte(_words)+"?";//検索ワード
str += "&max-results="+_results.toString();//件数
str += "&start-index="+(cnt*_results+1).toString();//インデックス
str += "&v=2";
//var loader:URLLoader = new URLLoader();
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE,onComplete);
var url:URLRequest = new URLRequest(str);
loader.load(url);
cnt++;
}
public function getImage(id:String,num:int=1):Sprite{
var loader:Loader;
loader = new Loader();
//const req:String = "http://www.ozworks.dip.jp/img/01/1426006.png";
const str1:String = "http://i.ytimg.com/vi/";
const str3:String = "/default.jpg";
const str4:String = "/0.jpg";
var req2:String;
switch(num){
case 0:
req2 = str1+id+str4;
break;
case 1:
req2 = str1+id+"/default.jpg";
break;
}
loader.load(new URLRequest(req2));//youtubeプレイヤー読み込み
var s:Sprite = new Sprite();
s.addChild(loader);
return s;
}
public var _xml:String;
private function onComplete(e:Event):void{
loader.removeEventListener(Event.COMPLETE,onComplete);
var res:XML = new XML(e.target.data);
var list:XMLList = res.children();
//var str:String = "";
var cnt:int=0;
for(var i:int=0;i<list.length();i++){
if(list[i].localName()!="entry")continue;
var list3:XMLList = list[i].elements();
for(var j:int=0;j<list3.length();j++){
if(list3[j].localName()=="title"){ //タイトル抽出
//str += list3[j].text()+"\n";
var title:String = new String();
title += list3[j].text();
titleList.push(title);
}
else if(list3[j].localName()=="id"){ //ID抽出
var str3:String = list3[j].text();
var n:int = str3.indexOf("video:")+6;
//var n:int = str3.indexOf("videos/")+7;
var id:String = str3.substring(n);
//str += id+"\n";
idList.push(id);
}
else if(list3[j].localName()=="author"){//投稿者名
var str4:String;
var list2:XMLList = list3[j].elements();
str4 = list2[0].text();
authorList.push(str4);
}
else if(list3[j].localName()=="group"){//再生時間
var str5:String = list3[j].toXMLString();
var n2:int = str5.indexOf('duration="')+10;
var n3:int = str5.indexOf('"',n2);
var n4:int = parseInt(str5.substring(n2,n3));
durationList.push(n4);
}//*/
}
//str += list3.elements("id").toXMLString()+"\n\n";
//str += i.toString()+" "+list[i].localName()+"\n";
//str += list[i].toXMLString()+"\n\n";
//str += "\n";
_xml = res.toXMLString();
}
//コンプリートイベント発行
var event:Event = new Event(Event.COMPLETE);
this.dispatchEvent(event);
}
}
//}
//player ver2
import flash.display.*;
import flash.net.*;
import flash.system.*;
import flash.events.*;
import flash.text.*;
class TubePlayer extends Sprite{
private var WIDTH:int = 320;
private var HEIGHT:int= 240;
private var player:Object;
//private var players:Array;
private var _state:int = -1;//プレイヤー状態
private var _seekTime:Number;
private var txt:TextField;
private var _id:String;
public function TubePlayer(w:int=320,h:int=240):void{
WIDTH=w;
HEIGHT=h;
var loader:Loader;
loader = new Loader();
Security.loadPolicyFile('http://www.youtube.com/crossdomain.xml');
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
const req:String = "http://www.youtube.com/apiplayer?enablejsapi=1&version=3";
loader.load(new URLRequest(req));//youtubeプレイヤー読み込み
txt = new TextField();
txt.textColor = 0x00ff00;
}
public function resize(w:int,h:int):void{
WIDTH = w;
HEIGHT = h;
if(player != null){
player.setSize(WIDTH, HEIGHT);//サイズ
}
}
//ローダー初期化
private function onLoaderInit(e:Event):void{
var loader:Loader = e.currentTarget.loader;
loader.content.addEventListener("onReady", onPlayerReady);
loader.content.addEventListener("onStateChange",onChangeState);
addChild(loader);
//addChild(txt);
}
public function get id():String{
return _id;
}
//音量
public function set volume(vol:Number):void{
player.setVolume(vol);
}
public function get volume():Number{
return player.getVolume();
}
//ミュート設定
public function set mute(b:Boolean):void{
if(b)player.mute();
else player.unMute();
}
public function get mute():Boolean{
return player.isMuted();
}
//IDを指定して動画を読み込む
public function load(id:String):void{
if(id==_id)return;
player.clearVideo();
player.cueVideoById(id);//動画ID
txt.appendText(id);
_id = id;
}
//IDを指定して動画を再生する。指定がなければ現在の動画を再生
public function play(id:String=null):void{
if(id!=null)load(id);
if(_id!=null)player.playVideo();//再生
}
public function pause():void{
player.pauseVideo();
}
public function stop():void{
player.stopVideo();
//seek = 0;
player.clearVideo();
}
public function get seek():Number{
if(_id==null)return 0;
return player.getCurrentTime();
}
public function set seek(time:Number):void{
if(_id!=null)player.seekTo(time);
}
public function get end():Number{
return player.getDuration();
}
public function get state():int{
return _state;
}
//プレイヤー設定
private function onPlayerReady(e:Event):void{
player = e.currentTarget;
player.setSize(WIDTH, HEIGHT);//サイズ
graphics.beginFill(0x000000);
graphics.drawRect(0,0,WIDTH,HEIGHT);
graphics.endFill();
}
//動画ステータス変化
private function onChangeState(e:Event):void{
_state = player.getPlayerState()
txt.appendText(_state.toString()+":");
//動画終了
if(state == 0){
txt.appendText("stop");
}
else if(_state == 1){
txt.appendText("play");
}
else if(_state == 2){
txt.appendText("pause");
}
//バッファリング中
else if(_state == 3){
txt.appendText("loading.....");
}
else if(_state == 5){//頭出し済み
txt.appendText("loading.....");
}
txt.appendText("\n");
txt.scrollV = txt.maxScrollV;
}
}//class
//}//package
//////////////////////////////////////////////////
// 吹出し
//////////////////////////////////////////////////
import flash.text.*;
import flash.display.*;
class InfoLabel extends Sprite{
private var _text:String ="";
private var _length:int;
public function InfoLabel(str:String=""){
_text = str;
this.mouseEnabled = this.mouseChildren = false;
draw();
}
public function set text(str:String):void{
_text = str;
draw();
_length = _text.length;
}
public function get length():int{
return _length;
}
//描画
private function draw():void{
while(0<this.numChildren)this.removeChildAt(0);
var tf:TextField = new TextField();
tf = new TextField();
tf.selectable = false;
tf.text = _text;
tf.width = tf.textWidth+5;
tf.height = tf.textHeight+5;
var c:uint = 0xdddddd;
var x1:Number= tf.width/2;
var y1:Number= tf.height+15;
var x2:Number= x1-5;
var x3:Number= x1+5;
var y2:Number= tf.height+5;
var s:Sprite = new Sprite();
with(s.graphics){
clear();
beginFill(c);
drawRoundRect(-10,-5,tf.width+20,tf.height+10,10,10);
endFill();
beginFill(c);
moveTo(x2,y2);
lineTo(x3,y2)
lineTo(x1,y1);
lineTo(x2,y2);
endFill();
}
s.addChild(tf);
s.x = -x1;
s.y = -y1;
s.alpha = 0.8;
this.addChild(s);
}
}
//////////////////////////////////////////////////
// Sliderクラス
//////////////////////////////////////////////////
import flash.display.*;;
import flash.filters.*;
import flash.geom.*;
import flash.events.*;
class Slider extends Sprite {
private var hole:Shape;
private var line:Sprite;
private var thumb:Sprite;
private var light:Shape;
private var shade:Shape;
private var base:Shape;
private var _width:uint = 100;
private var _height:uint = 3;
private static var bHeight:uint = 30;
private static var bColor:uint = 0xFFFFFF;
private static var bgColor:uint = 0x0099FF;
private static var sColor:uint = 0x000000;
private static var offColor:uint = 0x999999;
private var _min:Number = 0;//スライダー左端の値
private var _max:Number = 100;//スライダー右端の値
private var initValue:Number = 0;//リセット時の初期値
private var blueGlow:GlowFilter;
private var shadeDrop:DropShadowFilter;
private var _value:Number;
private var _enabled:Boolean = true;
private var info:InfoLabel = new InfoLabel();
public function Slider() {
}
public function init(option:Object):void {
if (option.width != undefined) _width = option.width;
if (option.min != undefined) _min = option.min;
if (option.max != undefined) _max = option.max;
if (option.init != undefined) initValue = option.init;
draw();
}
public function set max(n:Number):void{
if(n<_min)_max = _min;
_max = n;
}
public function set min(n:Number):void{
if(_max<n)_min=_max;;
_min = n;
}
//描画
private function draw():void {
while(0<this.numChildren)this.removeChildAt(0);
shadeDrop = new DropShadowFilter(1, 90, sColor, 0.5, 4, 4, 2, 3, false, false);
blueGlow = new GlowFilter(bgColor, 0.6, 5, 5, 2, 3, false, true);
hole = createGradientHole(_width, _height);
line = new Sprite();
thumb = new Sprite();
shade = createThumb(8, 20, 12, sColor);
shade.filters = [shadeDrop];
light = createThumb(8, 20, 12, bgColor);
light.filters = [blueGlow];
base = createThumb(8, 20, 12, bColor);
addChild(hole);
addChild(line);
//addChild(thumb);
thumb.addChild(shade);
thumb.addChild(light);
thumb.addChild(base);
hole.y = bHeight;
line.y = bHeight;
reset();
thumb.y = bHeight;
_up();
enabled = true;
thumb.mouseChildren = false;
}
//イベント設定
private function rollOver(evt:MouseEvent):void {
_over();
if(0<info.length)thumb.addChild(info);
info.y = -5;
}
private function rollOut(evt:MouseEvent):void {
_up();
thumb.removeChild(info);
}
private function press(evt:MouseEvent):void {
_down();
var rect:Rectangle = new Rectangle(0, bHeight, _width, 0);
thumb.startDrag(false, rect);
thumb.addEventListener(MouseEvent.MOUSE_UP, release, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_UP, release, false, 0, true);
stage.addEventListener(Event.MOUSE_LEAVE, leave, false, 0, true);
thumb.addEventListener(Event.ENTER_FRAME, change, false, 0, true);
isSlide=true;
}
private function release(evt:MouseEvent):void {
_up();
thumb.stopDrag();
checkValue();
var e:CompoEvent = new CompoEvent(CompoEvent.SELECT, _value);
dispatchEvent(e);
thumb.removeEventListener(MouseEvent.MOUSE_UP, release);
stage.removeEventListener(MouseEvent.MOUSE_UP, release);
stage.removeEventListener(Event.MOUSE_LEAVE, leave);
thumb.removeEventListener(Event.ENTER_FRAME, change);
isSlide=false;
}
private function leave(evt:Event):void {
_up();
thumb.stopDrag();
checkValue();
var e:CompoEvent = new CompoEvent(CompoEvent.SELECT, _value);
dispatchEvent(e);
thumb.removeEventListener(MouseEvent.MOUSE_UP, release);
stage.removeEventListener(MouseEvent.MOUSE_UP, release);
stage.removeEventListener(Event.MOUSE_LEAVE, leave);
thumb.removeEventListener(Event.ENTER_FRAME, change);
//isSlide=false;
}
private function _up():void {
light.visible = false;
}
private function _over():void {
light.visible = true;
}
private function _down():void {
light.visible = true;
}
private function _off():void {
light.visible = false;
}
private var isSlide:Boolean;
//
private function change(evt:Event):void {
_down();
checkValue();
var e:CompoEvent = new CompoEvent(CompoEvent.CHANGE, _value);
dispatchEvent(e);
lineDraw();
//time(_value);
}
//スライダーの状態から値を取得
private function checkValue():void {
_value = _min + Math.round(thumb.x/_width*(_max-_min));
}
public function get value():Number{
return _value;
}
public function set value(v:Number):void{
if(isSlide)return;
if(v<_min)_value = _min;
else if(_max<v)_value = _max;
else _value = v;
thumb.x = _width*(_value-_min)/(_max-_min);//スライダー位置の更新
lineDraw();
//time(_value);
}
private function time(s:Number):void{
var sec:int = s%60;
var minu:int = Math.floor(s/60)%60;
var hour:int = Math.floor(s/3600);
var str:String = "";
if(3600<_max)str+=hour.toString()+":";
if(60<_max)str+=minu.toString()+":";
if(0<_max)str+=sec.toString();
info.text = str;
}
private function lineDraw():void{
var w:uint = thumb.x;
var c:Number = _height;
with(line){
graphics.clear();
graphics.beginFill(0x44aaff,0.8);
graphics.drawRoundRect(-c, -c, w+c*2, c*2, c*2);
graphics.endFill();
}
}
//操作受付の設定 true:操作可能 false:操作不可
public function get enabled():Boolean {
return _enabled;
}
public function set enabled(param:Boolean):void {
_enabled = param;
if (!_enabled) _off();
thumb.buttonMode = _enabled;
thumb.mouseEnabled = _enabled;
thumb.useHandCursor = _enabled;
if (_enabled) {
thumb.addEventListener(MouseEvent.MOUSE_OVER, rollOver, false, 0, true);
thumb.addEventListener(MouseEvent.MOUSE_OUT, rollOut, false, 0, true);
thumb.addEventListener(MouseEvent.MOUSE_DOWN, press, false, 0, true);
thumb.addEventListener(MouseEvent.MOUSE_UP, release, false, 0, true);
addChild(thumb);
} else {
thumb.removeEventListener(MouseEvent.MOUSE_OVER, rollOver);
thumb.removeEventListener(MouseEvent.MOUSE_OUT, rollOut);
thumb.removeEventListener(MouseEvent.MOUSE_DOWN, press);
thumb.removeEventListener(MouseEvent.MOUSE_UP, release);
removeChild(thumb);
}
}
public function reset():void {
thumb.x = _width*(initValue-_min)/(_max-_min);//デフォルト位置に移動
_value = initValue;//デフォルト値に設定
lineDraw();
}
private function createThumb(w:uint, h:uint, y:uint, color:uint, alpha:Number = 1):Shape{
var target:Shape = new Shape();
target.graphics.beginFill(color, alpha);
target.graphics.drawRoundRect(-w*0.5, -y, w, h, w);
target.graphics.endFill();
return target;
}
private function createGradientHole(w:uint, c:Number):Shape{
var target:Shape = new Shape();
var colors:Array = [0x000000, 0x000000];
var alphas:Array = [0.4, 0];
var ratios:Array = [0, 255];
var matrix:Matrix = new Matrix();
matrix.createGradientBox(w+c*2, c*2, 0.5*Math.PI, -c, -c);
target.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0);
target.graphics.drawRoundRect(-c, -c, w+c*2, c*2, c*2);
target.graphics.endFill();
return target;
}
}
//////////////////////////////////////////////////
// IconBtnクラス
//////////////////////////////////////////////////
import flash.display.Sprite;
import flash.display.Shape;
import flash.filters.GlowFilter;
import flash.events.MouseEvent;
import flash.geom.ColorTransform;
class IconBtn extends Sprite {
public var id:uint;
private var shade:Shape;
private var bottom:Shape;
private var light:Shape;
private var base:Shape;
private var icon:Shape;
private var _width:uint = 60;
private static var _height:uint = 20;
private static var corner:uint = 5;
private var type:uint = 1;
private static var bColor:uint = 0xFFFFFF;
private static var sColor:uint = 0x000000;
private static var upColor:uint = 0x666666;
private static var overColor:uint = 0x333333;
private static var offColor:uint = 0x999999;
private static var upColorTrans:ColorTransform;
private static var overColorTrans:ColorTransform;
private static var offColorTrans:ColorTransform;
private var cColor:uint = 0x0099FF;
private var colorGlow:GlowFilter;
private var shadeGlow:GlowFilter;
private var _clicked:Boolean = false;
private var _enabled:Boolean = true;
public function IconBtn(Icon:Class) {
icon = new Icon();
}
public function setIcon(Icon:Class):void{
icon = new Icon();
draw();
}
public function init(option:Object):void {
if (option.id != undefined) id = option.id;
if (option.width != undefined) _width = option.width;
if (option.type != undefined) type = option.type;
if (option.color != undefined) cColor = option.color;
draw();
}
private function draw():void {
while(0<this.numChildren)this.removeChild(this.getChildAt(0));
switch (type) {
case 1 :
bColor = 0xFFFFFF;
sColor = 0x000000;
upColor = 0x666666;
overColor = 0x333333;
offColor = 0x999999;
break;
case 2 :
bColor = 0x000000;
sColor = 0xFFFFFF;
upColor = 0x666666;
overColor = 0x999999;
offColor = 0x333333;
break;
}
colorGlow = new GlowFilter(cColor, 0.6, 5, 5, 2, 3, false, true);
shadeGlow = new GlowFilter(sColor, 0.3, 4, 4, 2, 3, false, true);
upColorTrans = new ColorTransform();
upColorTrans.color = upColor;
overColorTrans = new ColorTransform();
overColorTrans.color = overColor;
offColorTrans = new ColorTransform();
offColorTrans.color = offColor;
shade = new Shape();
bottom = new Shape();
light = new Shape();
base = new Shape();
addChild(shade);
addChild(bottom);
addChild(light);
addChild(base);
addChild(icon);
createBase(shade, _width, _height, corner, sColor);
shade.filters = [shadeGlow];
createBase(bottom, _width, _height, corner, sColor, 0.3);
createBase(light, _width, _height, corner, cColor);
light.filters = [colorGlow];
createBase(base, _width, _height, corner, bColor);
icon.y = -1;
enabled = true;
mouseChildren = false;
}
private function rollOver(evt:MouseEvent):void {
_over();
}
private function rollOut(evt:MouseEvent):void {
_up();
}
private function press(evt:MouseEvent):void {
_down();
}
private function release(evt:MouseEvent):void {
_up();
}
private function click(evt:MouseEvent):void {
}
private function _up():void {
icon.y = -1;
icon.transform.colorTransform = upColorTrans;
base.y = -1;
light.visible = false;
light.y = -1;
}
private function _over():void {
icon.y = -1;
icon.transform.colorTransform = overColorTrans;
base.y = -1;
light.visible = true;
light.y = -1;
}
private function _down():void {
icon.y = 0;
icon.transform.colorTransform = overColorTrans;
base.y = 0;
light.visible = true;
light.y = 0;
}
private function _off():void {
icon.y = 0;
icon.transform.colorTransform = offColorTrans;
base.y = 0;
light.visible = false;
light.y = 0;
}
public function get clicked():Boolean {
return _clicked;
}
public function set clicked(param:Boolean):void {
_clicked = param;
if (_clicked) {
_down();
removeEventListener(MouseEvent.MOUSE_OVER, rollOver);
removeEventListener(MouseEvent.MOUSE_OUT, rollOut);
removeEventListener(MouseEvent.MOUSE_DOWN, press);
removeEventListener(MouseEvent.MOUSE_UP, release);
} else {
_up();
addEventListener(MouseEvent.MOUSE_OVER, rollOver, false, 0, true);
addEventListener(MouseEvent.MOUSE_OUT, rollOut, false, 0, true);
addEventListener(MouseEvent.MOUSE_DOWN, press, false, 0, true);
addEventListener(MouseEvent.MOUSE_UP, release, false, 0, true);
}
}
public function get enabled():Boolean {
return _enabled;
}
public function set enabled(param:Boolean):void {
_enabled = param;
buttonMode = _enabled;
mouseEnabled = _enabled;
useHandCursor = _enabled;
if (_enabled) {
_up();
addEventListener(MouseEvent.MOUSE_OVER, rollOver, false, 0, true);
addEventListener(MouseEvent.MOUSE_OUT, rollOut, false, 0, true);
addEventListener(MouseEvent.MOUSE_DOWN, press, false, 0, true);
addEventListener(MouseEvent.MOUSE_UP, release, false, 0, true);
addEventListener(MouseEvent.CLICK, click, false, 0, true);
} else {
_off();
removeEventListener(MouseEvent.MOUSE_OVER, rollOver);
removeEventListener(MouseEvent.MOUSE_OUT, rollOut);
removeEventListener(MouseEvent.MOUSE_DOWN, press);
removeEventListener(MouseEvent.MOUSE_UP, release);
removeEventListener(MouseEvent.CLICK, click);
}
}
private function createBase(target:Shape, w:uint, h:uint, c:uint, color:uint, alpha:Number = 1):void {
target.graphics.beginFill(color, alpha);
target.graphics.drawRoundRect(-w*0.5, -h*0.5, w, h, c*2);
target.graphics.endFill();
}
}
//////////////////////////////////////////////////
// Iconクラス
//////////////////////////////////////////////////
import flash.display.Shape;
class PlayIcon extends Shape {
public function PlayIcon() {
draw();
}
public function draw(c:uint=0):void {
graphics.clear();
graphics.beginFill(c);
graphics.moveTo(-4, -6);
graphics.lineTo(-4, 6);
graphics.lineTo(8, 0);
graphics.endFill();
}
}
class PauseIcon extends Shape {
public function PauseIcon() {
draw();
}
public function draw(c:uint=0):void {
graphics.clear();
graphics.beginFill(c);
graphics.drawRect(-5, -5, 4, 10);
graphics.endFill();
graphics.beginFill(c);
graphics.drawRect(3, -5, 4, 10);
graphics.endFill();
}
}
class StopIcon extends Shape {
public function StopIcon() {
draw();
}
private function draw(c:uint=0):void {
graphics.clear();
graphics.beginFill(c);
graphics.drawRect(-5, -5, 10, 10);
graphics.endFill();
}
}
class NextIcon extends Shape {
public function NextIcon() {
draw();
}
private function draw(c:uint=0):void {
graphics.clear();
graphics.beginFill(c);
graphics.moveTo(-14, -6);
graphics.lineTo(-14, 6);
graphics.lineTo(0, 0);
graphics.endFill();
graphics.beginFill(c);
graphics.moveTo(0, -6);
graphics.lineTo(0, 6);
graphics.lineTo(12, 0);
graphics.endFill();
graphics.beginFill(c);
graphics.drawRect(12,-6, 4, 12);
graphics.endFill();
}
}
class BackIcon extends Shape {
public function BackIcon() {
draw();
}
private function draw(c:uint=0):void {
graphics.clear();
graphics.beginFill(c);
graphics.moveTo(12, -6);
graphics.lineTo(12, 6);
graphics.lineTo(0, 0);
graphics.endFill();
graphics.beginFill(c);
graphics.moveTo(0, -6);
graphics.lineTo(0, 6);
graphics.lineTo(-12, 0);
graphics.endFill();
graphics.beginFill(c);
graphics.drawRect(-12,-5, 4, 10);
graphics.endFill();
}
}
class OpenIcon extends Shape {
public function OpenIcon() {
draw();
}
private function draw(c:uint=0):void {
graphics.clear();
graphics.beginFill(c);
graphics.drawRect(-8, -5, 16, 2);
graphics.endFill();
graphics.beginFill(c);
graphics.moveTo(-8, -1);
graphics.lineTo(8, -1);
graphics.lineTo(0, 6);
graphics.endFill();
}
}
class Vol0Icon extends Shape {
public function Vol0Icon() {
draw();
}
private function draw(c:uint=0):void {
graphics.clear();
graphics.beginFill(c);
graphics.moveTo(3-3, -6);
graphics.lineTo(3-3, 6);
graphics.lineTo(-6-3, 0);
graphics.endFill();
graphics.beginFill(c);
graphics.drawRect(-6-3,-3, 8, 6);
graphics.endFill();
}
}
class Vol1Icon extends Shape {
private static var bColor:uint = 0x000000;
public function Vol1Icon() {
draw();
}
private function draw(c:uint=0):void {
graphics.clear();
graphics.beginFill(c);
graphics.moveTo(3-3, -6);
graphics.lineTo(3-3, 6);
graphics.lineTo(-6-3, 0);
graphics.endFill();
graphics.beginFill(c);
graphics.drawRect(-6-3,-3, 8, 6);
graphics.endFill();
graphics.beginFill(c);
graphics.drawRect(2,-3, 2, 6);
graphics.endFill();
}
}
class Vol2Icon extends Shape {
public function Vol2Icon() {
draw();
}
private function draw(c:uint=0):void {
graphics.clear();
graphics.beginFill(c);
graphics.moveTo(3-3, -6);
graphics.lineTo(3-3, 6);
graphics.lineTo(-6-3, 0);
graphics.endFill();
graphics.beginFill(c);
graphics.drawRect(-6-3,-3, 8, 6);
graphics.endFill();
graphics.beginFill(c);
graphics.drawRect(2,-3, 2, 6);
graphics.endFill();
graphics.beginFill(c);
graphics.drawRect(5,-5, 2, 10);
graphics.endFill();
}
}
class Vol3Icon extends Shape {
public function Vol3Icon() {
draw();
}
private function draw(c:uint=0):void {
graphics.clear();
graphics.beginFill(c);
graphics.moveTo(3-3, -6);
graphics.lineTo(3-3, 6);
graphics.lineTo(-6-3, 0);
graphics.endFill();
graphics.beginFill(c);
graphics.drawRect(-6-3,-3, 8, 6);
graphics.endFill();
graphics.beginFill(c);
graphics.drawRect(2,-3, 2, 6);
graphics.endFill();
graphics.beginFill(c);
graphics.drawRect(5,-5, 2, 10);
graphics.endFill();
graphics.beginFill(c);
graphics.drawRect(8,-7, 2, 14);
graphics.endFill();
}
}
class MuteIcon extends Shape {
public function MuteIcon() {
draw();
}
private function draw(c:uint=0):void {
graphics.clear();
graphics.beginFill(c);
graphics.moveTo(3-3, -6);
graphics.lineTo(3-3, 6);
graphics.lineTo(-6-3, 0);
graphics.endFill();
graphics.beginFill(c);
graphics.drawRect(-6-3,-3, 8, 6);
graphics.endFill();
graphics.lineStyle(2,c);
graphics.moveTo(3+6, -3);
graphics.lineTo(-3+6, 3);
graphics.moveTo(3+6, 3);
graphics.lineTo(-3+6, -3);
}
}
//////////////////////////////////////////////////
// CompoEventクラス
//////////////////////////////////////////////////
import flash.events.Event;
class CompoEvent extends Event {
public static const SELECT:String = "select";
public static const CHANGE:String = "change";
public var value:*;
public function CompoEvent(type:String, value:*) {
super(type);
this.value = value;
}
public override function clone():Event {
return new CompoEvent(type, value);
}
}
///////////////////////////////////////////////////
// SearchBar
///////////////////////////////////////////////////
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.geom.*;
class SearchBar extends Sprite{
private var input:TextField;
private var icon:SearchIcon = new SearchIcon();
private var color1:uint = 0x000000;
private var color2:uint = 0xaaaaaa;
private var color3:uint = 0x0088ff;
public var btn:Sprite;
public function SearchBar():void{
var a:Shape = createGradientHole(120,13);
addChild(a);
input = new TextField();
input.type ="input";
input.y =-10;
input.addEventListener(Event.CHANGE,onChange);
input.addEventListener(KeyboardEvent.KEY_DOWN,pressKey);
input.addEventListener(KeyboardEvent.KEY_UP,releaseKey);
addChild(input);
btn = new Sprite();
btn.addChild(icon);
icon.x = -2;
btn.graphics.beginFill(0,0);
btn.graphics.drawRect(-12,-10,24,20);
btn.graphics.endFill();
btn.x = 120;
btn.buttonMode = true;
btn.addEventListener(MouseEvent.MOUSE_OVER,rollOver);
btn.addEventListener(MouseEvent.MOUSE_OUT,rollOut);
btn.addEventListener(MouseEvent.MOUSE_DOWN,press);
btn.addEventListener(MouseEvent.MOUSE_UP,release);
addChild(btn);
rollOut();
}
public function set text(str:String):void{
input.text = str;
onChange();
}
public function get text():String{
return input.text;
}
private function createGradientHole(w:uint, c:Number):Shape{
var target:Shape = new Shape();
var colors:Array = [0x0033aa, 0x00aaff];
var alphas:Array = [0.4, 0];
var ratios:Array = [0, 255];
var matrix:Matrix = new Matrix();
matrix.createGradientBox(w+c*2, c*2, 0.5*Math.PI, -c, -c);
target.graphics.beginFill(0xffffff);
target.graphics.drawRoundRect(-c, -c, w+c*2, c*2, c*2);
target.graphics.endFill();
target.graphics.lineStyle(2,0x555555,0.9);
target.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0);
target.graphics.drawRoundRect(-c, -c, w+c*2, c*2, c*2);
target.graphics.endFill();
return target;
}
private function onChange(e:Event=null):void{
var overColorTrans:ColorTransform = new ColorTransform();
if(input.text.length==0)overColorTrans.color = color2;
else overColorTrans.color = color1;
icon.transform.colorTransform = overColorTrans;
}
private function pressKey(e:KeyboardEvent):void{
if(e.keyCode==13 && 0<input.text.length){
press();
var ev:MouseEvent = new MouseEvent(MouseEvent.CLICK);
btn.dispatchEvent(ev);
}
}
private function releaseKey(e:KeyboardEvent):void{
release();
}
private function rollOver(e:MouseEvent=null):void {
var overColorTrans:ColorTransform = new ColorTransform();
overColorTrans.color = color3;
icon.transform.colorTransform = overColorTrans;
}
private function rollOut(e:MouseEvent=null):void {
var overColorTrans:ColorTransform = new ColorTransform();
if(input.text.length==0)overColorTrans.color = color2;
else overColorTrans.color = color1;
icon.transform.colorTransform = overColorTrans;
}
private function press(e:MouseEvent=null):void {
icon.y = 1;
}
private function release(e:MouseEvent=null):void {
icon.y = 0;
}
}
//検索
class SearchIcon extends Shape {
private static var bColor:uint = 0x000000;
public function SearchIcon() {
draw();
}
private function draw():void {
graphics.beginFill(bColor);
graphics.drawCircle(0,-1,5);
graphics.drawCircle(0,-1,6.5);
graphics.endFill();
graphics.lineStyle(3,bColor);
graphics.moveTo(-7,7);
graphics.lineTo(-4,4);
}
}
//シークバー
import flash.display.*;
import flash.events.*;
import flash.ui.*;
import flash.text.*;
import flash.geom.*;
class SeekBar extends Sprite{
private var thumb:Sprite=new Sprite();
private var _width:Number = 300;
private var _height:Number = 20;
private var _value:Number = 1.0;
private var color1:uint = 0x44aaff;
private var color2:uint = 0x223388;//青
private var color3:uint = 0xff0000;//シークポイント
private var isSlide:Boolean;
private var isOver:Boolean;
private var _length:Number = 1.0;
private var info:InfoLabel = new InfoLabel();
public function SeekBar(){
init();
this.mouseChildren = false;
}
private function init():void{
draw();
this.addEventListener(MouseEvent.MOUSE_OVER,onMouse);
this.addEventListener(MouseEvent.MOUSE_OUT,outMouse);
this.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
this.addEventListener(MouseEvent.MOUSE_MOVE,onMove);
}
public function setSize(w:Number=300,h:Number=20):void{
_width = w;
_height= h;
draw(_value);
}
public function setColor(c1:uint,c2:uint=0x333333,c3:uint=0xff0000):void{
color1 = c1;
color2 = c2;
color3 = c3;
draw(_value);
}
public function set length(n:Number):void{
_length=n;
_value = 0;
draw(_value);
}
public function get length():Number{
return _length;
}
public function set value(n:Number):void{
if(isSlide)return;
_value=n;
if(n<0)_value=0;
if(_length<n)_value=_length;
draw(_value);
}
public function get value():Number{
return _value;
}
//シークバー描画
private function draw(n:Number=0):void{
var p:Number=n;
if(p<0)p=0;
if(_length<p)p=_length;
var par:Number = p/_length;
with(this.graphics){
clear();
beginFill(color1,0);
drawRect(-10,-10,_width+20,_height+20);
endFill();
beginFill(color1);
drawRect(0,0,_width,_height);
endFill();
beginFill(color2);
//drawRect(0,0,seekWidth*par,10);
drawRect(_width*par,0,_width*(1.0-par),_height);
endFill();
}
if(isOver)draw2();
}
//シークポイントの描画
private function draw2():void{
var sx:Number = this.mouseX;
if(sx<0)sx=0;
if(_width<sx)sx=_width;
var t:Number = _length * (sx/_width);
var s:int = Math.floor(t%60);
var m:int = Math.floor((t/60)%60);
var h:int = Math.floor(t/3600);
var str:String = new String();
if(3600<_length)str += h.toString()+":";
if(60<_length)str += m.toString()+":";
if(0<_length)str+=s.toString();
info.text =str;
info.x = sx;
with(this.graphics){
beginFill(color3);
drawRect(sx,0,3,_height);
endFill();
}
}
//シーク
private function onDown(e:MouseEvent):void{
this.addEventListener(MouseEvent.MOUSE_UP, onUp, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_UP, onUp, false, 0, true);
stage.addEventListener(Event.MOUSE_LEAVE, leave, false, 0, true);
value = _length * (this.mouseX/_width);
isSlide=true;
//this.addEventListener(MouseEvent.MOUSE_MOVE,onMove);
}
private function onUp(e:MouseEvent):void{
var e2:CompoEvent = new CompoEvent(CompoEvent.CHANGE, _value);
dispatchEvent(e2);
this.removeEventListener(MouseEvent.MOUSE_UP, onUp);
stage.removeEventListener(MouseEvent.MOUSE_UP, onUp);
stage.removeEventListener(Event.MOUSE_LEAVE, leave);
isSlide=false;
//this.removeEventListener(MouseEvent.MOUSE_MOVE,onMove);
}
private function leave(e:Event):void {
//thumb.stopDrag();
//checkValue();
var e2:CompoEvent = new CompoEvent(CompoEvent.SELECT, _value);
dispatchEvent(e2);
this.removeEventListener(MouseEvent.MOUSE_UP, onUp);
stage.removeEventListener(MouseEvent.MOUSE_UP, onUp);
stage.removeEventListener(Event.MOUSE_LEAVE, leave);
//isSlide=false;
}
private function onMove(e:MouseEvent):void{
if(isSlide)_value = _length * (this.mouseX/_width);
draw(_value);
//draw2();
}
private function onMouse(e:MouseEvent):void{
Mouse.cursor = MouseCursor.BUTTON;
isOver=true;
if(0<info.length)this.addChild(info);
}
private function outMouse(e:MouseEvent):void{
Mouse.cursor = MouseCursor.AUTO;
isOver=false;
draw(_value);
this.removeChild(info);
}
}