蚊
forked from Button (diff: 28)
「Click me!」の文字の周りを回っているのがボタンです。 まあ、ありがちだけどこれはこれで。 と言うか、押せる気がしないんですが。
ActionScript3 source code
/**
* Copyright atsushi015 ( http://wonderfl.net/user/atsushi015 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/jYMM
*/
// forked from Event's Button
package {
import flash.display.Sprite;
import flash.text.TextField;
public class ButtonContainer extends Sprite {
public function ButtonContainer() {
var button:Button = new Button;
button.setText('Click me!');
button.x = 200; button.y = 200;
addChild(button);
var lab:TextField = new TextField();
lab.width = 400;
lab.height = 18;
lab.x = button.x;
lab.y = button.y - 20;
lab.alpha = 70;
lab.textColor = 0;
lab.text = 'Click me!';
addChild(lab);
stage.scaleMode = "noScale";
stage.align = "tl";
}
}
}
import flash.display.*;
import flash.events.MouseEvent;
import flash.text.TextFormat;
import flash.text.TextField;
import flash.events.Event;
class Button extends Sprite {
protected var _label:TextField;
protected var _tfmOver:TextFormat = new TextFormat('_serif', 14, 0);
protected var _tfmOut:TextFormat = new TextFormat('_serif', 14, 0xffffff);
protected var _overSkin:Shape;
protected var count:int;
public function Button() {
_label = new TextField;
_label.defaultTextFormat = _tfmOut;
_label.x = _label.y = 1;
_overSkin = new Shape;
count = 0;
addEventListener(Event.ADDED_TO_STAGE, function _init(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, _init);
init();
});
}
protected function init():void {
buttonMode = true;
tabEnabled = false;
_label.mouseEnabled = false;
addChild(_overSkin);
addChild(_label);
addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
addEventListener(MouseEvent.MOUSE_OUT, mouseOut);
addEventListener(Event.ENTER_FRAME, loop);
mouseOut(null);
}
protected function loop(e:Event):void {
var frequency:int = 25;
x = 200 + Math.cos(count / frequency * 3) * 100;
y = 200 + Math.sin(count / frequency * 5) * 100;
count++;
}
protected function mouseOver(e:MouseEvent):void {
_overSkin.visible = true;
_label.setTextFormat(_tfmOver);
}
protected function mouseOut(e:MouseEvent):void {
_overSkin.visible = false;
_label.setTextFormat(_tfmOut);
}
public function setText(value:String):void {
_label.text = value;
_label.width = 1;
_label.height = 1;
draw(graphics, 0x000000, 0x333333);
draw(_overSkin.graphics, 0xbbbbbb, 0xcccccc);
}
private function draw(g:Graphics, lineColor:uint, fillColor:uint):void {
g.clear();
g.lineStyle(2, lineColor);
g.beginFill(fillColor);
g.drawRect(0, 0, _label.width, _label.height);
g.endFill();
}
}