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

クリックしにくい

Get Adobe Flash player
by bkzen 01 Oct 2010
/**
 * Copyright bkzen ( http://wonderfl.net/user/bkzen )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ij1I
 */

/**
 * クリックしにくいオブジェクトをクリックしやすくするには
 * どうしたらよいでしょうか?
 */
package  
{
    import flash.display.Sprite;
    public class Test extends Sprite 
    {
        public function Test() 
        {
            for (var i: int = 0; i < 10; i++) 
                addChildAt(new TestChild(i), Math.random() < 0.5 ? numChildren : 0);
        }
        
    }

}
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.filters.GlowFilter;
import flash.geom.Rectangle;
class TestChild extends Sprite
{
    private var sp: Sprite;
    private static var FILTER: GlowFilter = new GlowFilter(0xFF0000, 1, 6, 6, 3);
    function TestChild(index: int)
    {
        // ここから
        mouseChildren = false;
        x = ((index % 5) + 1) * 25, y = ((index / 5 | 0) + 1) * 25 + 100;
        // ここまでを変更不可
        
        addChild(sp = makeGraphic(index));
        //var r: Rectangle = sp.getBounds(null);
        //var hitAreaRect: Sprite = new Sprite();
        //var g: Graphics = hitAreaRect.graphics;
        //g.beginFill(0xFFFFFF, 0.001);
        //g.drawRect(r.x, r.y, r.width, r.height);
        //addChild(hitAreaRect);
        //hitArea = hitAreaRect;
        buttonMode = true;
        addEventListener(MouseEvent.MOUSE_OVER, onOver);
        addEventListener(MouseEvent.MOUSE_OUT, onOut);
    }
    
    // ここは変更不可
    private function makeGraphic(index: int): Sprite 
    {
        var s: Sprite = new Sprite();
        var g: Graphics = s.graphics;
        g.beginFill(0x004080);
        var n: int = Math.random() * 5 + 10;
        // 適当に斜めに描画
        for (var i:int = 0; i < n; i++) 
        {
            var w: int = 70 * ((index % 2) ? (n - i) : i) / n;
            var sy: int = i * 5 - n * 4;
            g.drawRect(w, sy, w, 1);
        }
        return s;
    }
    
    private function onOut(e: MouseEvent): void {  sp.filters = null;   }
    private function onOver(e: MouseEvent): void {  sp.filters = [FILTER];   }
}