FP10.2 の MouseCursorData(DL無し)
FlashPlayer10.2 のテスト
Wonderfl で直接は見れないけど、
ダウンロード無しに見れるようにしてみた。
@author jc at bk-zen.com
/**
* Copyright bkzen ( http://wonderfl.net/user/bkzen )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/uzFT
*/
// forked from bkzen's FlashPlayer10.2 の MouseCursorData
/**
* FlashPlayer10.2 のテスト
* Wonderfl で直接は見れないけど、
* ダウンロード無しに見れるようにしてみた。
* @author jc at bk-zen.com
*/
package
{
import flash.display.Graphics;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.DropShadowFilter;
import flash.system.Capabilities;
import flash.ui.Mouse;
[SWF (backgroundColor = "0xFFFFFF", frameRate = "30", width = "465", height = "465")]
public class Main extends Sprite
{
private var square:Sprite;
public function Main():void
{
new FP102Tester(this, init);
}
private function init():void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
//
CursolManager.init();
square = new Sprite();
var g: Graphics = square.graphics;
g.beginFill(0x006699);
g.drawRect(0, 0, 150, 100);
square.x = stage.stageWidth - square.width >> 1, square.y = stage.stageHeight - square.height >> 1;
square.filters = [new DropShadowFilter(2, 90, 0x000000, 1, 4, 4, 1, 3)];
square.addEventListener(MouseEvent.ROLL_OVER, onMouseHandler);
square.addEventListener(MouseEvent.ROLL_OUT, onMouseHandler);
square.addEventListener(MouseEvent.MOUSE_DOWN, onMouseHandler);
square.addEventListener(MouseEvent.MOUSE_UP, onMouseHandler);
addChild(square);
}
private function onMouseHandler(e:MouseEvent):void
{
Mouse["cursor"] = e.type;
switch(e.type)
{
case MouseEvent.MOUSE_DOWN:
square.startDrag();
break;
case MouseEvent.MOUSE_UP:
square.stopDrag();
break;
}
}
}
}
class FP102Tester
{
import com.bit101.components.Label;
import com.bit101.components.PushButton;
import flash.display.DisplayObjectContainer;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.system.Capabilities;
private var _main: DisplayObjectContainer;
private var _initHandler: Function;
function FP102Tester(main: DisplayObjectContainer, initHandler: Function)
{
_main = main, _initHandler = initHandler;
_main.loaderInfo.addEventListener(Event.COMPLETE, onComp);
}
private function onComp(e:Event):void
{
_main.loaderInfo.removeEventListener(Event.COMPLETE, onComp);
var b: Boolean = _main.loaderInfo.swfVersion == 11;
var vers: Array = Capabilities.version.split(" ")[1].split(",");
if (vers[0] >= 10 && vers[1])
{
if (b)
{
_main = null;
var f: Function = _initHandler;
_initHandler = null;
f();
}
else
{
new PushButton(_main, 100, 120, "Test", openTest);
}
}
else
{
var l: Label = new Label(_main, 0, 0, "Please Install FlashPlayer10.2");
l.move(_main.stage.stageWidth - l.width >> 1, _main.stage.stageHeight - l.height >> 1);
}
}
private function openTest(e: MouseEvent):void
{
var url: String = _main.loaderInfo.url;
url = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("."));
navigateToURL(new URLRequest("http://wonderfl.bk-zen.com/fp102/?id=" + url));
}
}
import flash.display.BitmapData;
import flash.display.Shape;
import flash.events.MouseEvent;
import flash.ui.Mouse;
//import flash.ui.MouseCursorData;
import flash.utils.getDefinitionByName;
class CursolManager
{
public static function init(): Boolean
{
sh = new Shape();
Mouse["registerCursor"](MouseEvent.ROLL_OVER, getMCD(Vector.<BitmapData>([getC1()])));
Mouse["registerCursor"](MouseEvent.MOUSE_DOWN, getMCD(Vector.<BitmapData>([getC2()])));
Mouse["registerCursor"](MouseEvent.MOUSE_UP, getMCD(Vector.<BitmapData>([getC3()])));
Mouse["registerCursor"](MouseEvent.ROLL_OUT, getMCD(Vector.<BitmapData>([getC4()])));
return true;
}
private static var sh: Shape;
private static function getMCD(cursolBmds: Vector.<BitmapData>): *
{
cursolBmds.fixed = true;
var c: Class = getDefinitionByName("flash.ui.MouseCursorData") as Class;
var m: * = new c();
m.data = cursolBmds;
return m;
//var mcd: MouseCursorData = new MouseCursorData();
//mcd.data = cursolBmds;
//return mcd;
}
private static function getC1(): BitmapData
{
var bmd: BitmapData = new BitmapData(32, 32, true, 0x00000000);
sh.graphics.clear();
PathUtils.drawXTL(sh.graphics, 0xFF00FF, 32);
bmd.draw(sh);
return bmd;
}
private static function getC2(): BitmapData
{
var bmd: BitmapData = new BitmapData(32, 32, true, 0x00000000);
sh.graphics.clear();
PathUtils.drawCheckTL(sh.graphics, 0xFF0000, 32);
bmd.draw(sh);
return bmd;
}
private static function getC3(): BitmapData
{
var bmd: BitmapData = new BitmapData(32, 32, true, 0);
// 何も描画しないと真っ黒になるらしい。
return bmd;
}
private static function getC4(): BitmapData
{
var bmd: BitmapData = new BitmapData(32, 32, true, 0x00000000);
sh.graphics.clear();
PathUtils.drawXCenter(sh.graphics, 0x0000FF, 32);
bmd.draw(sh);
return bmd;
}
}
//package com.bkzen.utils
//{
import flash.display.Graphics;
/**
* PathUtils
* @author jc at bk-zen.com
*/
class PathUtils
{
//{ region drawX
public static function drawXCenter(
g: Graphics, color: uint, size: Number, x: Number = 0, y: Number = 0, isFill: Boolean = true
): void
{
if (isFill) g.beginFill(color);
var r: Number = size / 2;
var l: Number = r / 4;
var a: Number = l * Math.sqrt(2);
var angle: Number = Math.atan2(l, r);
g.moveTo(x + a, y + 0);
for (var i:int = 0; i < 4; i++)
{
var rad: Number = Math.PI * (0.25 + i * 0.50);
g.lineTo(x + r * Math.cos(rad - angle), y + r * Math.sin(rad - angle));
g.lineTo(x + r * Math.cos(rad + angle), y + r * Math.sin(rad + angle));
rad = Math.PI * (i + 1) * 0.50;
g.lineTo(x + a * Math.cos(rad), y + a * Math.sin(rad));
}
}
public static function drawXTL(
g: Graphics, color: uint, size: Number, x: Number = 0, y: Number = 0, isFill: Boolean = true
): void
{
var r: Number = size / 2;
drawXCenter(g, color, size, x + r, y + r, isFill);
}
//} endregion
//{ region drawCheck
public static function drawCheckTL(
g: Graphics, color: uint, size: Number = 15, x: Number = 0, y: Number = 0, isFill: Boolean = true
): void
{
if (isFill) g.beginFill(color);
var s: Number = size / 15;
g.moveTo( 3 * s + x, 6 * s + y);
g.lineTo( 5 * s + x, 11 * s + y);
g.lineTo( 7 * s + x, 11 * s + y);
g.lineTo( 12 * s + x, 3 * s + y);
g.lineTo( 13 * s + x, 2 * s + y);
g.lineTo( 11 * s + x, 2 * s + y);
g.lineTo(6.5 * s + x, 8 * s + y);
g.lineTo( 5 * s + x, 6 * s + y);
g.lineTo( 3 * s + x, 6 * s + y);
}
public static function drawCheckCenter(
g: Graphics, color: uint, size: Number = 15, x: Number = 0, y: Number = 0, isFill: Boolean = true
): void
{
var r: Number = size / 2;
drawCheckTL(g, color, size, x - r, y - r, isFill);
}
//} endregion
}
//}