[英]AS3 Object moves to random location within stage onClick
我正在嘗試制作一個對象,一個紅色圓圈會彈跳到我點擊舞台上的隨機位置,並顯示you touched my circle
的消息。 我不太清楚我在做什么錯。
這是我想出的
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;
}
您需要設置圓的新坐標,為此使用x
和y
屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.