如何通过拖动其子持有者来重新调整圆圈的大小?

时间:2013-05-14 06:35:29

标签: actionscript-3

我想通过拖动其子容器动画片段来调整圆圈的大小。任何身体都能告诉我如何在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;

3 个答案:

答案 0 :(得分: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();
}

答案 1 :(得分: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();
}

答案 2 :(得分:0)

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