HelpPanel (2)
HelpPanel (2)
/**
* Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/w5cl
*/
////////////////////////////////////////////////////////////////////////////////
// HelpPanel (2)
////////////////////////////////////////////////////////////////////////////////
package {
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.Event;
import flash.events.MouseEvent;
[SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]
public class Main extends Sprite {
private var btn:Sprite;
private var help:HelpPanel;
public function Main() {
//Wonderfl.capture_delay(1);
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
init();
}
private function init():void {
btn = new Sprite();
addChild(btn);
btn.x = 232;
btn.y = 232;
btn.graphics.beginFill(0xFF0000);
btn.graphics.drawRect(-50, -50, 100, 100);
btn.graphics.endFill();
btn.addEventListener(MouseEvent.MOUSE_OVER, rollOver, false, 0, true);
btn.addEventListener(MouseEvent.MOUSE_OUT, rollOut, false, 0, true);
//
help = new HelpPanel();
addChild(help);
help.x = 232;
help.y = 532;
}
private function rollOver(evt:MouseEvent):void {
help.show("help!");
}
private function rollOut(evt:MouseEvent):void {
help.hide();
}
}
}
//////////////////////////////////////////////////
// HelpTipクラス
//////////////////////////////////////////////////
import flash.display.Sprite;
import flash.display.Shape;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.filters.DropShadowFilter;
import flash.events.Event;
import flash.events.MouseEvent;
class HelpPanel extends Sprite {
private var base:Sprite;
private var panel:Shape;
private var arrow:Shape;
private var board:Shape;
private var txt:TextField;
private static var fontType:String = "_ゴシック";
private var px:uint;
private var py:uint;
private static var _width:uint = 100;
private static var _height:uint = 30;
private static var xOffset:uint = 15;
private static var yOffset:uint = 10;
private static var bColor:uint = 0xFFFFFF;
private static var sColor:uint = 0x000000;
private static var cColor:uint = 0xEEEEEE;
private static var tColor:uint = 0x000000;
private var shade:DropShadowFilter;
private var deceleration:Number = 0.25;
private var step:uint = 10;
private var _visible:Boolean = false;
public function HelpPanel() {
draw();
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
}
// メソッド
private function init(evt:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
visible = false;
x = stage.stageWidth*0.5;
y = stage.stageHeight*0.5;
addEventListener(Event.ENTER_FRAME, update, false, 0, true);
mouseChildren = false;
mouseEnabled = false;
}
private function draw():void {
shade = new DropShadowFilter(1, 90, sColor, 0.4, 4, 4, 1.5, 2, false, false);
base = new Sprite();
panel = new Shape();
arrow = new Shape();
board = new Shape();
txt = new TextField();
addChild(base);
base.addChild(panel);
base.addChild(arrow);
base.addChild(board);
base.addChild(txt);
createBox(panel, -_width*0.5, -_height, _width, _height, 4);
createArrow(arrow, 6, 8);
createBase(board, -_width*0.5+5, -_height+5, _width-10, _height-10);
base.y = - yOffset;
txt.x = -_width*0.5 + 8;
txt.y = -_height + 6;
txt.width = _width - 16;
txt.height = _height - 2;
txt.type = TextFieldType.DYNAMIC;
txt.selectable = false;
txt.multiline = true;
txt.wordWrap = true;
txt.antiAliasType = AntiAliasType.ADVANCED;
var tf:TextFormat = new TextFormat();
tf.font = fontType;
tf.size = 12;
tf.align = TextFormatAlign.CENTER;
txt.defaultTextFormat = tf;
txt.textColor = tColor;
filters = [shade];
}
private function update(evt:Event):void {
var xMouse:uint = stage.mouseX;
var yMouse:uint = stage.mouseY;
if (xMouse >= 0 && xMouse <= stage.stageWidth) {
px += (xMouse - px)*deceleration;
py += (yMouse - py)*deceleration;
}
x = Math.round(px);
y = Math.round(py);
showPanel();
}
private function showPanel():void {
var a:Number = 1/step;
if (_visible) {
visible = true;
alpha += a;
if (alpha >= 1) alpha = 1;
} else {
alpha -= a;
if (alpha <= 0) {
alpha = 0;
visible = false;
}
}
}
public function show(t:String):void {
txt.text = t;
_visible = true;
}
public function hide():void {
_visible = false;
}
private function createBox(target:Shape, x:int, y:int, w:uint, h:uint, c:uint):void {
target.graphics.beginFill(bColor);
target.graphics.drawRoundRect(x, y, w, h, c*2);
target.graphics.endFill();
}
private function createArrow(target:Shape, w:uint, h:uint):void {
target.graphics.beginFill(bColor);
target.graphics.moveTo(0, 0);
target.graphics.lineTo(-w*0.5, 0);
target.graphics.lineTo(0, h);
target.graphics.lineTo(w*0.5, 0);
target.graphics.lineTo(0, 0);
target.graphics.endFill();
}
private function createBase(target:Shape, x:int, y:int, w:uint, h:uint):void {
target.graphics.beginFill(cColor);
target.graphics.drawRect(x, y, w, h);
target.graphics.endFill();
}
}