In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: FlashPlayer10.2 の MouseCursorData

/**
 * Copyright hacker_mx_95scj ( http://wonderfl.net/user/hacker_mx_95scj )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kZmn
 */

// forked from bkzen's FlashPlayer10.2 の MouseCursorData
/**
 * FlashPlayer10.2 のテスト
 * Wonderfl では観れないので、Download Button を押して、
 * ダウンロードして動作をチェックして見てください。
 * @author jc at bk-zen.com
 */
package 
{
    import com.bit101.components.Label;
    import com.bit101.components.PushButton;
    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.net.FileReference;
    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;
        private var file:FileReference;
        
        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            // entry point
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            //
            var vers: Array = Capabilities.version.split(" ")[1].split(",");
            if (vers[0] >= 10 && vers[1]) 
            {
                start();
            }
            else 
            {
                new Label(this, 100, 100, "Please Install FlashPlayer10.2");
            }
        }
        
        private function start(): void 
        {
            if (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);
            }
            else 
            {
                var label: Label = new Label(this, 100, 100, "Download and flashPlayer10_2test.swf play.");
                var btn: PushButton = new PushButton(this, 100, 120, "Download", onSave);
                loaderInfo.bytes[3] = 0x0B;
                file = new FileReference();
            }
        }
        
        private function onSave(e: Event): void 
        {
            file.save(loaderInfo.bytes, "flashPlayer10_2test.swf");
        }
        
        private function onMouseHandler(e:MouseEvent):void 
        {
            if (!Mouse["cursor"]) return;
            Mouse["cursor"] = e.type;
            switch(e.type)
            {
                case MouseEvent.MOUSE_DOWN:
                    square.startDrag();
                    break;
                case MouseEvent.MOUSE_UP:
                    square.stopDrag();
                    break;
            }
        }
    }
}
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
    {
        if (!Mouse["registerCursor"]) return false;
        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
}
//}