AS3中可能的颜色错误

时间:2016-09-23 14:27:17

标签: actionscript-3 flash colors

我写了一个关于用鼠标移动的板的AS3程序(.swf输出),但是当我将颜色设置为蓝色时,结果是围绕蓝色内部区域的板的黄色外部区域。当用户点击屏幕时,它才变为完全蓝色。如何修改程序,以便在程序开始时电路板变为蓝色而不单击一次?该计划已上传到此链接:http://titusngiscoding.wixsite.com/movingboard

以下是源代码,全部内容。

package 
{
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    public class FlashTest extends Sprite 
    {
        public var board:Sprite;
        public function FlashTest() 
        {
            board = new Sprite();
            addChild(board);
            board.graphics.beginFill(0x0099ff);
            board.graphics.drawRect(0,stage.stageWidth-20,100,10);
            board.graphics.endFill();
            board.x = stage.stageWidth /2 - board.width/2;
            stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseEvent);
            stage.focus = board;
        }
        public function onMouseEvent(event:MouseEvent):void
        {
            board.x = event.localX - board.width/2;
            if(board.x <0)
                board.x = 0;
            if(board.x > stage.stageWidth - board.width)
                board.x = stage.stageWidth - board.width;
        }
    }
}

1 个答案:

答案 0 :(得分:1)

1) stage.focus = board;此行会导致黄色轮廓,删除它或解释您需要它的原因。

2) board.graphics.drawRect(0,stage.stageWidth-20,100,10);为什么将stageWidth设为Y-pos ??

也许你想要: board.graphics.drawRect(0,stage.stageHeight-20,100,10);

PS:如果你愿意,不要忘记board.x = event.localX board.x = stage.mouseX