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

android4.2 animation

AS勉強開始3日目です。
とりあえずandroid4.2のアニメーションを書いてみたかったので書きました。
参考 http://about-hiroppy.com/pictures/android4.2_animation.png

なぜかアップした画像の背景が透明にならずに困っています>< ローカルではできるのに。。。(A. wonderflが強制的にjpgに拡張子をかえるため)
Get Adobe Flash player
by about 10 Feb 2013
/**
 * Copyright about ( http://wonderfl.net/user/about )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kDo0
 */

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Matrix;
    
    public class android_animation extends Sprite
    {
        private var canvas:Sprite = new Sprite();
        private var ob:Vector.<android_icon> = new Vector.<android_icon>;
        private var s:Number = 50;
        private var a:Number = 1.0;
        private var dx:Number;
        private var dy:Number;
        private var curcleX:Number;
        private var curcleY:Number;
        private var targetX:Number;
        private var targetY:Number;
        private var preX:Number=0;
        private var preY:Number=0;
        private var counter:int=0;
        private var mouse_vx:Number;
        private var mouse_vy:Number;
        private var rest_num:Number = s;    
        public function android_animation()
        {
            addChild(canvas);
            for(var i:int=0;i<s;i++){
                ob.push(new android_icon());
            }
            
            var m:Matrix=new Matrix();
            graphics.beginGradientFill("linear", [0x4682B4, 0x0], [1.0, 1.0], [0, 255], m);
            graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
            graphics.endFill();
            
            for(i=0;i<ob.length;i++){
                ob[i].x = Math.random()*(stage.stageWidth);
                ob[i].y = Math.random()*(stage.stageHeight);
                // 初速
                ob[i].vx = Math.random()*10-5;
                ob[i].vy = Math.random()*10-5;
                canvas.addChild(ob[i]);
            }
            
            canvas.addEventListener(Event.ENTER_FRAME,onEnterFrame);
            canvas.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
            canvas.addEventListener(MouseEvent.MOUSE_UP,mouseUp);
        }
        
        private function onEnterFrame(e:Event):void{
            for(var i:int = 0;i<ob.length;i++){
                if(!ob[i].flg){
                    ob[i].x += ob[i].vx;
                    ob[i].y += ob[i].vy
                }
                if(ob[i].x > stage.stageWidth+50){
                    ob[i].x = stage.stageWidth+50;
                    ob[i].vx *= -0.1;
                    if(ob[i].stage_flg) ob[i].x = stage.stageWidth+200;
                }
                else if(ob[i].x < -50){
                    ob[i].x = -50;
                    ob[i].vx *= -0.1;
                    if(ob[i].stage_flg) ob[i].x=-200;
                }
                if(ob[i].y > stage.stageHeight+50){
                    ob[i].y = stage.stageHeight+50;
                    ob[i].vy *= -0.1;
                    if(ob[i].stage_flg) ob[i].stage.stageHeight+200;
                }
                else if(ob[i].y < -50){
                    ob[i].y = -50;
                    ob[i].vy *= -0.1;
                    if(ob[i].stage_flg) ob[i].y = -200;
                }
            }
            
            mouse_vx += mouseX-preX;
            mouse_vy += mouseY-preY;
            preX = mouseX;
            preY = mouseY;
            counter++;
        }
        
//        private function onMouseMove(e:MouseEvent):void{
//            mouse_vx += mouseX-preX;
//            mouse_vy += mouseY-preY;
//            preX = mouseX;
//            preY = mouseY;
//            counter++;
//        }
        
        private function mouseUp(e:MouseEvent):void{
            e.target.stopDrag();
            targetX = mouseX - curcleX;
            targetY = mouseY - curcleY;
            
            e.target.vx = mouse_vx/counter*2;
            e.target.vy = mouse_vy/counter*2;
            e.target.stage_flg=true;
            e.target.flg = false;
        }
        
        private function mouseDown(e:MouseEvent):void{
            e.target.startDrag();
            curcleX = e.target.x;
            curcleY = e.target.y;
            counter = 0;
            preX = mouseX;
            preY = mouseY;
            mouse_vx = 0;
            mouse_vy = 0;
            e.target.flg = true;
        }
    }
}
import flash.system.LoaderContext;
import flash.text.TextField;

import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;

class android_icon extends Sprite{
    public var flg:Boolean = false; //マウスでもってるか持ってないかのflag
    public var stage_flg:Boolean = false;
    public var vx:Number, vy:Number;
    public var icon:Sprite = new Sprite();
    private var url:String = "http://assets.wonderfl.net/images/related_images/e/e6/e6cc/e6cc3ba4f536d2a37059a763d23a4330ade3109am";
    
    public function android_icon():void{
        var loader:Loader=new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadComplete);
        loader.load(new URLRequest(url), new LoaderContext(true));
    }
    
    private function loadComplete(e:Event):void{
        var lo:Loader = Loader(e.target.loader);
        var bitmap:Bitmap = Bitmap(lo.content);
        bitmap.height = 60;
        bitmap.width = 60;
        addChild(bitmap);
    }
}