1

我想通过拖动它的子持有者movieclip来调整一个圆圈的大小,任何人都可以告诉我如何在as3中这样做。它就像转换movielcip

到目前为止,这是我的代码:

var pupil:MovieClip=new MovieClip();
var holder:MovieClip=new MovieClip();

pupil.graphics.lineStyle(1, 0x000000);
pupil.x = pupil.y = 100;
pupil.graphics.beginFill(0xFF0000, .1);
pupil.graphics.drawCircle(0, 0, 20);
pupil.graphics.endFill();

holder.graphics.beginFill(0xFF0000);
holder.graphics.drawCircle(pupil.width/2,0, 4);
holder.graphics.endFill();

addChild(pupil);
pupil.addChild(holder);

holder.buttonMode = true;
4

3 回答 3

2

试试下面的代码,我希望这是你需要的。

import flash.events.MouseEvent;
import flash.geom.Point;
import flash.events.Event;

var pupil:MovieClip=new MovieClip();
var holder:MovieClip=new MovieClip();
var newPoint:Point = new Point();

var dist:Number;

pupil.graphics.lineStyle(1, 0x0000FF);
pupil.x = pupil.y = 100;
pupil.graphics.beginFill(0x0000FF, .1);
pupil.graphics.drawCircle(0, 0, 50);
//pupil.graphics.endFill();

holder.graphics.beginFill(0xFF0000);
holder.graphics.drawCircle(0,0, 5);
holder.graphics.endFill();

holder.x = pupil.width/2;

addChild(pupil);
pupil.addChild(holder);

holder.buttonMode = true;

holder.addEventListener(MouseEvent.MOUSE_DOWN, onHolderClikded);
holder.addEventListener(MouseEvent.MOUSE_UP, onHolderReleased);
function onHolderClikded(eve:MouseEvent):void{

    holder.startDrag();


    addEventListener(Event.ENTER_FRAME, onPointMoving)

}

function onPointMoving(eve:Event):void{

    newPoint.x = holder.x;
    newPoint.y = holder.y;
    dist = Point.distance(new Point(0,0),newPoint.clone());
    pupil.graphics.clear();
    pupil.graphics.lineStyle(1, 0x0000FF);
    pupil.graphics.beginFill(0x0000FF, .1);
    pupil.graphics.drawCircle(0, 0, dist);
}


function onHolderReleased(eve:MouseEvent):void{
    holder.stopDrag();
}
于 2013-05-14T08:02:55.203 回答
1

这应该让你开始。

var pupil:MovieClip = new MovieClip();
pupil.x = stage.stageWidth / 2;
pupil.y = stage.stageHeight / 2;
addChild(pupil);


var holder:MovieClip = new MovieClip();
holder.buttonMode = true;
holder.graphics.beginFill(0xFF0000);
holder.graphics.drawCircle(0, 0, 4);
holder.graphics.endFill();
pupil.addChild(holder);

holder.addEventListener(MouseEvent.MOUSE_DOWN, mouse);
holder.addEventListener(MouseEvent.MOUSE_UP, mouse);


function mouse(e:MouseEvent):void
{
    switch(e.type)
    {
        case MouseEvent.MOUSE_DOWN:
            addEventListener(Event.ENTER_FRAME, update);
        break;

        case MouseEvent.MOUSE_UP:
            removeEventListener(Event.ENTER_FRAME, update);
        break;
    }
}


function update(e:Event):void
{
    holder.x = pupil.mouseX;
    holder.y = pupil.mouseY;

    var d:Number = Math.sqrt(holder.x * holder.x + holder.y * holder.y);

    pupil.graphics.clear();
    pupil.graphics.lineStyle(1, 0x000000);
    pupil.graphics.beginFill(0xFF0000, .1);
    pupil.graphics.drawCircle(0, 0, d);
    pupil.graphics.endFill();
}
于 2013-05-14T07:09:23.137 回答
0

获取绝对 x/y 坐标(相对于 c 的阶段)并对圆形父级本身执行相同操作。获取差异,应用 sqrt( x*x + y*y ) 与这些坐标之间的距离,你应该得到半径或直径(取决于注册点是否在圆的中心)。

于 2013-05-14T07:08:30.103 回答