简体   繁体   中英

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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM