JAVAC.JP
HOSHI TETSUYA ―“S–ξ
2005/07/25
hossy@javac.jp
http://www.javac.jp
Google
WWW ‚πŒŸυ WWW.JAVAC.JP ‚πŒŸυ

A-3 ‰Ϋ‘θ3 - ‰π“š

‰Ϋ‘θ(3-1)
TestClass.as
---
import mx.events.EventDispatcher;

class TestClass extends MovieClip{
    var button_a:MovieClip;
    var button_b:MovieClip;
    var button_c:MovieClip;
    var namefield:TextField;

    function TestClass(){
        EventDispatcher.initialize(button_a);
        button_a.onRelease=function(){
            var lo:Object=new Object();
            lo.target=this;
            lo.type="showMessage";
            lo.message="APPLE";
            this.dispatchEvent(lo);
        }
        button_a.addEventListener("showMessage",this);

        EventDispatcher.initialize(button_b);
        button_b.onRelease=function(){
            var lo:Object=new Object();
            lo.target=this;
            lo.type="showMessage";
            lo.message="BANANA";
            this.dispatchEvent(lo);
        }
        button_b.addEventListener("showMessage",this);

        EventDispatcher.initialize(button_c);
        button_c.onRelease=function(){
            var lo:Object=new Object();
            lo.target=this;
            lo.type="showMessage";
            lo.message="CHEESE";
            this.dispatchEvent(lo);
        }
        button_c.addEventListener("showMessage",this);
    }

    function showMessage(eventObj:Object):Void{
        var message:String=String(eventObj.message);
        namefield.text=message;
    }
}
‰Ϋ‘θ(3-2)
main.as
---
var main:MainClass=new MainClass(this);
stop();

OvalClass.as
---
class OvalClass extends MovieClip{
    private var count:Number;
    private var v:Number;
    private var alpha:Number;

    function OvalClass(){
        var arr:Array=[
            0xFFFFAA,
            0xFFAAFF,
            0xAAFFFF,
            0xAAAAFF,
            0xAAFFAA,
            0xFFAAAA
        ];
        var colorObj:Color=new Color(this);
        colorObj.setRGB(arr[Math.floor(arr.length*Math.random())]);
        count=0;
        alpha=100;
    }

    function setPosition(x:Number,y:Number):Void{
        _x=x;
        _y=y;
    }

    function setVelocity(v:Number):Void{
        this.v=v;
    }

    function setAlpha():Void{
        _alpha=alpha;
    }

    function setScale(scale:Number):Void{
        _xscale=scale;
        _yscale=scale;
    }

    function onEnterFrame():Void{
        count++;
        alpha--;
        setAlpha();
        _x+=v;
        if(count>=100){
            this.removeMovieClip();
        }
    }
}

MainClass.as
---
import mx.events.EventDispatcher;

class MainClass{
    private var path:MovieClip;
    private var mouseListener:MovieClip;
    private var DEPTH_MOUSELISTENER:Number=100;
    private var DEPTH_OVALS:Number=200;
    private var DEPTH_OVAL_START:Number=0;
    private var old_x:Number;
    private var old_y:Number;
    private var depth_oval:Number;

    function MainClass(path:MovieClip){
        this.path=path;
        path.createEmptyMovieClip("mc_mouselistener",DEPTH_MOUSELISTENER);
        path.createEmptyMovieClip("mc_ovals",DEPTH_OVALS);
        mouseListener=path.mc_mouselistener;
        EventDispatcher.initialize(mouseListener);
        mouseListener.onMouseMove=function(){
            var lo:Object=new Object();
            lo.target=this;
            lo.type="onMouseMoveHandler";
            lo.x=this._parent._xmouse;
            lo.y=this._parent._ymouse;
            this.dispatchEvent(lo);
        }
        mouseListener.addEventListener("onMouseMoveHandler",this);
        old_x=0;
        old_y=0;
        depth_oval=DEPTH_OVAL_START;
    }

    function onMouseMoveHandler(eventObj):Void{
        var new_x:Number=Number(eventObj.x);
        var new_y:Number=Number(eventObj.y);
        var r:Number=Math.sqrt((new_x-old_x)*(new_x-old_x)
                                +(new_y-old_y)*(new_y-old_y));
        var v:Number=(new_x-old_x)*r/Math.abs(new_x-old_x);
        if(Math.abs(v)>5){
            var linkage:String="oval";
            var depth:Number=depth_oval;
            depth_oval++;
            var mcname:String="oval"+depth;
            path.mc_ovals.attachMovie(linkage,mcname,depth);
            var mc:MovieClip=path.mc_ovals[mcname];
            mc.setPosition(new_x,new_y);
            mc.setScale(Math.abs(v));
            mc.setVelocity(v);
        }
        old_x=new_x;
        old_y=new_y;
    }
}
‰Ϋ‘θ(3-3)
TestClass.as
---
import mx.events.EventDispatcher;

class TestClass extends MovieClip{
    var test_button:MovieClip;
    var depth:Number;

    function TestClass(){
        EventDispatcher.initialize(test_button);
        test_button.onPress=function(){
            var lo:Object=new Object();
            lo.target=this;
            lo.type="onPressHandler";
            this.dispatchEvent(lo);
        }
        test_button.addEventListener("onPressHandler",this);
        depth=0;
    }

    function onPressHandler():Void{
        var linkage:String="oval";
        var mcname:String="oval"+depth;
        this.attachMovie(linkage,mcname,depth);
        depth++;
        this[mcname].setPosition(_xmouse,_ymouse);
    }
}

OvalClass.as
---
import mx.events.EventDispatcher;

class OvalClass extends MovieClip{
    var mouseListener:MovieClip;

    function OvalClass(){
        this.createEmptyMovieClip("mouseListener",1);
        EventDispatcher.initialize(mouseListener);
        mouseListener.onMouseUp=function(){
            var lo:Object=new Object();
            lo.target=this;
            lo.type="onMouseUpHandler";
            this.dispatchEvent(lo);
        }
        mouseListener.addEventListener("onMouseUpHandler",this);
        this.startDrag(true,50,50,350,250);
    }

    function onMouseUpHandler():Void{
        this.stopDrag();
        mouseListener.removeMovieClip();
    }

    function onPress():Void{
        this.startDrag(true,50,50,350,250);
    }

    function onRelease():Void{
        this.stopDrag();
    }

    function onReleaseOutside():Void{
        this.stopDrag();
    }

    function setPosition(x:Number,y:Number):Void{
        _x=x;
        _y=y;
    }
}



BACKTOPNEXT




All Contents Copyright (C) 2005 HOSHI Tetsuya
Home