daChubbs
01-17-2012, 11:03 PM
hi, i am new to actionscript 3.0 and am having trouble with a game i am building. It is a game where you click an image then it will display another image randomly somewhere else. I am currently having trouble with setting boundaries on the image so that it will not leave the stage. Here is my code so far plz help!
import flash.events.MouseEvent;
stop();
smily.addEventListener(MouseEvent.CLICK,sClick)
function sClick(event:MouseEvent):void{
smily.x = randomNumberX();
smily.y = randomNumberY();
//-- set image location --\\
checkBoundaries();
nextFrame();
//-- when smily clicked go to next frame--\\
}
function randomNumberX(low:Number=0, high:Number=640):Number
{
return Math.floor(Math.random() * (1+high-low)) + low;
//-- generate random x coordinate --\\
}
function randomNumberY(low:Number=0, high:Number=360):Number
{
return Math.floor(Math.random() * (1+high-low)) + low;
//-- generate random y coordinate --\\
}
function checkBoundaries():void{
if(smily.x > stage.stageWidth)
smily.x = stage.stageWidth - smily.width;
if(smily.y > stage.stageHeight)
smily.y = stage.stageHeight - smily.height;
}
import flash.events.MouseEvent;
stop();
smily.addEventListener(MouseEvent.CLICK,sClick)
function sClick(event:MouseEvent):void{
smily.x = randomNumberX();
smily.y = randomNumberY();
//-- set image location --\\
checkBoundaries();
nextFrame();
//-- when smily clicked go to next frame--\\
}
function randomNumberX(low:Number=0, high:Number=640):Number
{
return Math.floor(Math.random() * (1+high-low)) + low;
//-- generate random x coordinate --\\
}
function randomNumberY(low:Number=0, high:Number=360):Number
{
return Math.floor(Math.random() * (1+high-low)) + low;
//-- generate random y coordinate --\\
}
function checkBoundaries():void{
if(smily.x > stage.stageWidth)
smily.x = stage.stageWidth - smily.width;
if(smily.y > stage.stageHeight)
smily.y = stage.stageHeight - smily.height;
}