0

我编辑了以下代码,以便让那些绿色矩形跟随我的光标,该光标由一个小矩形自定义。但是我遇到了几个问题:

  1. 虽然我没有在单独的类中定义任何坐标,但是在发布阶段,光标坐标只有一半大小时,大小显然是错误的。
  2. 尽管我在其他代码中测试得很好,但无法激活重置按钮。这是我发表的作品:http: //neowudesign.com/hwu_ex04.html

时间线上的代码

//hw//Creating a new cursor 
newcursor.startDrag ("true");
Mouse.hide();


//hw//Creating a holder to hold the butterfly objects 
var mothHolder = new Sprite();
addChild(mothHolder);

//hw//Creating seven moths at the beginning 
makeMoths(7);

//hw//creating a function which can generate limited numbers of moths.
function makeMoths(MothsNumber:Number)
{
for (var i = 0; i < MothsNumber; i++)
{
    newMoth = new Moth();
    mothHolder.addChild(newMoth);
}
}


//hw//Set the reset button at the top for clicking, but it's failed to work;
//hw//Set the cursor back to the default one, and remove the custom one when hovering;
mothHolder.setChildIndex(reset,mothHolder.numChildren);

reset.addEventListener(MouseEvent.MOUSE_OVER, cursorchange);
function cursorchange(event:MouseEvent):void
{   
Mouse.show();
newcursor.visible = false;
trace("alert!!");
}


//hw//creating a function of reset 
reset.addEventListener(MouseEvent.CLICK, resetClick, false, 0, true);
function resetClick(evt:MouseEvent):void
{
removeChild(mothHolder);
mothHolder = new MovieClip();
addChild(mothHolder);
var numMoths:Number = Math.round(Math.random() * 6) + 1;
trace("Moths Numeber: "+ numMoths);
makeButterflies(numButterflies);
}


//hw//when the cursor leave the reset region, it turns back to the customized one
reset.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler);
function fl_MouseOutHandler(event:MouseEvent):void
{
removeEventListener(MouseEvent.MOUSE_OVER, cursorchange);
Mouse.hide();
newcursor.visible = true;
}

而“Moth”类的代码分别命名为“angle.as”

package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.geom.Point;

public class angle extends MovieClip {

    var speed:Number = 8;   
    function angle() {
        //letting every moth follow the moving of the cursor
        addEventListener(Event.ENTER_FRAME,mothMove);

        function mothMove(myEvent:Event) {

            trace(mouseX);
            trace(mouseY);
            var angle:Number = Math.atan2(mouseY - y, mouseX - x);
            x += Math.cos( angle ) * speed;
            y += Math.sin( angle ) * speed;
        }
    }   
}
}
4

0 回答 0