AS3中的相对坐标问题

时间:2013-05-06 01:44:54

标签: actionscript-3

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

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

    //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;
            }
        }   
    }
    }
    

0 个答案:

没有答案