Groups | Blog | Home
all groups > flash actionscript > april 2007 >

flash actionscript : Button Problem


Flash Cus
4/13/2007 8:54:03 PM
Ok, so i was experimenting with the random function. I decided to create a
circle (converted to movie clip), and a button. My idea was to push the button,
and the circle would move to a random point on the screen. I have the standard
550x400 size, and my code is the following:

xrand = random(551);
yrand = random(401)

btn.onRelease = function()
{
cir._x = xrand;
cir._y = yrand;
};

It seems to work, but it only works once. After that the button does nothing.
I've tried converting the button to a movie clip. Is there something wrong with
my actionscript?

Cheers
kglad
4/13/2007 8:59:18 PM
well, it may not look like it's doing anything but it's actually re-executing
your code. the problem is xrand and yrand having changed since the previous
button press so you see nothing happening.

to remedy:



btn.onRelease = function()
{
xrand = random(551);
yrand = random(401)
cir._x = xrand;
cir._y = yrand;
};
Flash Cus
4/13/2007 9:43:58 PM
kglad
4/15/2007 12:00:00 AM
AddThis Social Bookmark Button