[英]AS3 Object moves to random location within stage onClick
I'm trying to make an object, a red circle move bounce to a random location within my stage onCLick, and display the message you touched my circle
. 我正在尝试制作一个对象,一个红色圆圈会弹跳到我点击舞台上的随机位置,并显示you touched my circle
的消息。 I don't quite know what i'm doing wrong. 我不太清楚我在做什么错。
Here is what i came up with 这是我想出的
import flash.events.MouseEvent;
myCircle.addEventListener(MouseEvent.MOUSE_DOWN, onClick);
function onClick(e:MouseEvent):void
{
trace("you touched myCircle");
Math.floor(Math.random()*(1+High-Low))+Low;
}
var High = stage.stageWidth == 550, stage.stageHeight == 400;
var Low = stage.stageWidth == 0, stage.stageHeight == 0;
var HighH:int=stage.stageHeight;
var HighW:int=stage.stageWidth;
var LowH:int=0; var LowW:int=0;
....
function onClick(e:MouseEvent):void
{
trace("you touched myCircle");
myCircle.x=Math.floor(Math.random()*(1+HighW-LowW))+LowW;
myCircle.y=Math.floor(Math.random()*(1+HighH-LowH))+LowH;
}
You need to set your circle's new coordinates, use x
and y
properties for that. 您需要设置圆的新坐标,为此使用x
和y
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.