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

プチプチボタン

こんなボタンならいっぱい「いいね!」してもらえる・・・かも。
※「いいね!」機能自体はダミーなので、気兼ねなくプチプチしてください。

SEは以下のサイトのものを使わせていただきました。
http://koukaongen.com/
Get Adobe Flash player
by chabudai 30 Sep 2010
/**
 * Copyright chabudai ( http://wonderfl.net/user/chabudai )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/nDTZ
 */

//こんなボタンならいっぱい「いいね!」してもらえる.....かも。
//※「いいね!」機能自体はダミーなので、気兼ねなくプチプチしてください。
//
//SEは以下のサイトのものを使わせていただきました。
//http://koukaongen.com/
package  
{
    import flash.display.Bitmap;
    import flash.display.Loader;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.TimerEvent;
    import flash.media.Sound;
    import flash.media.SoundLoaderContext;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.utils.Timer;
    
    import caurina.transitions.Tweener;
    
    [SWF(width = "465", height = "465", frameRate = "30", backgroundColor = "#ACC8CD")]
    
    public class Puchi extends Sprite
    {
        private var _seURL1:String = "http://chabudai.org/temp/wonderfl/puchi/gum.mp3";
        private var _seURL2:String = "http://chabudai.org/temp/wonderfl/puchi/straw.mp3";
        private var _urlList:Array = ["http://chabudai.org/temp/wonderfl/puchi/icon.png", "http://chabudai.org/temp/wonderfl/puchi/puchi01.png", "http://chabudai.org/temp/wonderfl/puchi/puchi02.png", "http://chabudai.org/temp/wonderfl/puchi/puchi03.png"];
        private var _likeCount:int = 0;
        private var _loadCompleteNum:int = 1;
        private var _loader0:Loader = new Loader();
        private var _loader1:Loader = new Loader();
        private var _loader2:Loader = new Loader();
        private var _loader3:Loader = new Loader();
        private var _loaderList:Array = [_loader0, _loader1, _loader2, _loader3];
        private var _sound1:Sound;
        private var _sound2:Sound;
        private var _text:TextField;
        private var _timer:Timer;
        private var _buttonList:Array = [];
        private var _pushList:Array = [];
        
        public function Puchi() 
        {
            for (var i:int = 0; i < 4; i++) 
            {
                _loaderList[i].load(new URLRequest(_urlList[i]), new LoaderContext(true));
                _loaderList[i].contentLoaderInfo.addEventListener(Event.COMPLETE, _loadComplete);
            }
            _sound1 = new Sound();
            _sound1.load(new URLRequest(_seURL1), new SoundLoaderContext(100, true));
            _sound1.addEventListener(Event.COMPLETE, _loadComplete);
            
            _sound2 = new Sound();
            _sound2.load(new URLRequest(_seURL2), new SoundLoaderContext(100, true));
            _sound2.addEventListener(Event.COMPLETE, _loadComplete);
        }
        
        private function _loadComplete(e:Event):void 
        {
            if (_loadCompleteNum >= 6) {
                _init();
            }else {
                _loadCompleteNum++;
            }
        }
        
        private function _init():void 
        {
            var shape:Shape = new Shape;
            shape.graphics.beginFill(0xFFFFFF, 0.6);
            shape.graphics.drawRect(0, 425, 465, 40);
            shape.graphics.endFill();
            addChild(shape);
            
            _loader0.x = 10;
            _loader0.y = 441;
            addChild(_loader0);
            
            _text = new TextField();
            _text.x = 26;
            _text.y = 440;
            _text.autoSize = "left";
            _text.text = _likeCount + "人が「いいね!」と言っています。";
            _text.setTextFormat(new TextFormat("_等幅", 10, 0x333333));
            addChild(_text);
            
            for (var i:int = 0; i < 7; i++) 
            {
                for (var j:int = 0; j < 4; j++) 
                {
                    var puchiButton:PuchiButton;
                    if (i == 6 && j == 3) {
                        puchiButton = new PuchiButton(Bitmap(_loader3.content), Bitmap(_loader2.content), _sound1, _sound2);
                        puchiButton.addEventListener(MouseEvent.CLICK, _onReset);
                        puchiButton._id = 51;
                        _buttonList[51] = puchiButton;
                    }else{
                        puchiButton = new PuchiButton(Bitmap(_loader1.content), Bitmap(_loader2.content), _sound1, _sound2);
                        puchiButton.addEventListener(MouseEvent.CLICK, _onClick);
                        var num:int = i +(j * 15);
                        puchiButton._id = num;
                        _buttonList[num] = puchiButton;
                    }
                    puchiButton.x = 68 * i + 24;
                    puchiButton.y = 120 * j + 25;
                    addChild(puchiButton);
                }
            }
            for (i = 0; i < 8; i++) 
            {
                for (j = 0; j < 3; j++) 
                {
                    puchiButton = new PuchiButton(Bitmap(_loader1.content), Bitmap(_loader2.content), _sound1, _sound2);
                    puchiButton.addEventListener(MouseEvent.CLICK, _onClick);
                    num = i +(j * 15) + 7;
                    _buttonList[num] = puchiButton;
                    puchiButton._id = num;
                    puchiButton.x = 68 * i - 12;
                    puchiButton.y = 120 * j + 85;
                    addChild(puchiButton);
                }
            }
            _timer = new Timer(25, 52);
            _timer.addEventListener(TimerEvent.TIMER, _onTimer);
            _timer.start();
        }
        
        private function _onClick(e:MouseEvent):void 
        {
            _pushList.push(e.target);
            _likeCount++;
            _text.text = _likeCount + "人が「いいね!」と言っています";
            _text.setTextFormat(new TextFormat("_等幅", 10, 0x333333));
            e.target.mouseEnabled = false;
        }
        
        private function _onTimer(e:TimerEvent = null):void
        {
            var num:int = _timer.currentCount - 1;
            _buttonList[num].reset();
            Tweener.addTween(_buttonList[num], { visible:true, scaleX:1, scaleY:1, time:0.3, transition:"easeOutBack" } );
            if (num % 4 == 0)_sound2.play();
        }
        
        private function _onReset(e:MouseEvent):void 
        {
            if (_pushList.length < 1) {
                _buttonList[51].reset();
                _buttonList[51].scaleX = _buttonList[51].scaleY = 1;
                return;
            }
            _pushList.sortOn("_id", Array.NUMERIC);
            _timer = new Timer(25, _pushList.length);
            _timer.addEventListener(TimerEvent.TIMER, _onTimerReset);
            _timer.addEventListener(TimerEvent.TIMER_COMPLETE, _onTimerComplete);
            _timer.start();
        }
        
        private function _onTimerReset(e:TimerEvent):void 
        {
            var num:int = _timer.currentCount - 1;
            _pushList[num].reset();
            Tweener.addTween(_pushList[num], { visible:true, scaleX:1, scaleY:1, time:0.3, transition:"easeOutBack" } );
            if (num % 4 == 0)_sound2.play();
        }
        
        private function _onTimerComplete(e:TimerEvent):void 
        {
            _buttonList[51].reset();
            _buttonList[51].scaleX = _buttonList[51].scaleY = 1;
            _pushList = [];
        }
        
    }
}

//button
import flash.display.Bitmap;
import flash.display.GradientType;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.media.Sound;
class PuchiButton extends Sprite
{
    public var _id:int;
    private var _puchi1:Bitmap;
    private var _puchi2:Bitmap;
    private var _sound1:Sound;
    private var _sound2:Sound;
    private var _mask:Sprite;
    private var _shadow:Sprite;
    
    public function PuchiButton(a:Bitmap, b:Bitmap, s1:Sound, s2:Sound)
    {
        visible = false;
        
        _puchi1 = new Bitmap(a.bitmapData.clone());
        _puchi2 = new Bitmap(b.bitmapData.clone());
        _puchi2.visible = false;
        _puchi1.x = _puchi2.x = -51;
        _puchi1.y = _puchi2.y = -43;
        _puchi1.smoothing = _puchi2.smoothing = true;
        addChild(_puchi1);
        addChild(_puchi2);
        
        _sound1 = s1;
        _sound2 = s2;
        
        _mask = new Sprite();
        _mask.graphics.beginFill(0xFFFFFF, 1);
        _mask.graphics.drawCircle(0, 0, 27);
        _mask.graphics.endFill();
        addChild(_mask);
        
        var hit:Sprite = new Sprite();
        hit.graphics.beginFill(0xFFFFFF, 0);
        hit.graphics.drawCircle(0, 0, 30);
        hit.graphics.endFill();
        addChild(hit);
        
        _shadow = new Sprite();
        _shadow.graphics.beginGradientFill(GradientType.RADIAL, 
        [ 0x61909F, 0x61909F, 0x61909F], [ 0.7 , 0.2, 0], [ 0 , 15, 30]);
        _shadow.graphics.drawCircle(0, 0, 16);
        _shadow.graphics.endFill();
        _shadow.visible = false;
        _shadow.mask = _mask;
        addChild(_shadow);
        
        hitArea = hit;
        buttonMode = true;
        mouseChildren = false;
        
        addEventListener(MouseEvent.MOUSE_OVER, _onOver);
        addEventListener(MouseEvent.MOUSE_OUT, _onOut);
        addEventListener(MouseEvent.MOUSE_DOWN, _onDown);
        addEventListener(MouseEvent.MOUSE_MOVE, _onMove);
    }
    
    public function reset():void {
        scaleX = scaleY = 0.7;
        _puchi1.visible = true;
        _puchi2.visible = false;
        mouseEnabled = true;
    }
    
    private function _onDown(e:MouseEvent):void {
        _puchi1.visible = false;
        _puchi2.visible = true;
        _sound1.play();
    }
    private function _onMove(e:MouseEvent):void {
        _shadow.x = mouseX;
        _shadow.y = mouseY;
    }
    private function _onOver(e:MouseEvent):void {
        _shadow.x = mouseX;
        _shadow.y = mouseY;
        _shadow.visible = true;
    }
    private function _onOut(e:MouseEvent):void {
        _shadow.visible = false;
    }
}