I want to create a button that "can't be clicked on", as in, when the cursor is near it, the button randomly changes it's position (within stage limitations). not sure how to look it up online, so i'm asking here :)
Asked
Active
Viewed 52 times
2 Answers
0
This is pretty simple.
Add an eventlistener for
MouseEvent.MOUSE_OVER
on yourDisplayObject
When the event triggers, create two values (
x
andy
) randomly within the stage bounds (taking width/height of theDisplayObject
into account as well)assign those values to the
x
andy
properties of yourDisplayObject
And that's it.
-
1You should also make sure your object has set _tabEnabled_ to false, in order to prevent using the tab key to focus the element and then by pressing enter triggering it – Jan Jun 30 '15 at 09:46
0
var button:Sprite = new Sprite();
button.addEventListener(MouseEvent.MOUSE_OVER, moveButton);
function moveButton(event:MouseEvent):void
{
button.x = Math.random() * stage.x;
button.y = Math.random() * stage.y;
}
if you want to make the button move away before the mouse cursor actually touched it, you should add a transparent sprite larger than the button and place on top of it

MasterWil
- 891
- 8
- 24