PDA

View Full Version : [AS3] MOUSE_OVER help


flips30240
12-28-2009, 08:28 PM
Im trying to make a simple maze where when the mouse hits the wall the mouse resets back to the starting point. Im using the MOUSE_OVER function and that's where i get stuck. heres the code so far.

var wall:Shape = new Shape();
wall.addEventListener(MouseEvent.MOUSE_OVER, denied);

function denied(event:MouseEvent) :void {
if (


and thats where my brilliant ideas stop.... im not sure what to put in the if statement to make the program realize the mouse is touching the wall and it needs to reset. ( I just started as3 a few days ago so im pretty bad ) thanks in advance for any help!

tadster
12-28-2009, 08:50 PM
hmmm.. make the actual users mouse move backwards? Even if you did that they would just move it again. Or do you mean somehting like make it invisible over the shape?

import flash.ui.Mouse;
wall.addEventListener(MouseEvent.MOUSE_OVER, denied);
wall.addEventListener(MouseEvent.MOUSE_OUT, backAgain);
function denied(event:MouseEvent):void {
Mouse.hide();
}
function backAgain(yeayeayea:MouseEvent):void {
Mouse.show();
}

flips30240
12-28-2009, 09:02 PM
you know like the scary maze game kinda thing where when you touch the wall the mouse is reset to the beginning, ill give what you posted a try =) thanks for fast response!

flips30240
12-28-2009, 09:03 PM
edit : still not working =(

flips30240
12-28-2009, 09:43 PM
Alright, seeing s im new and probably doing something wrong aside from the code im gonna go into more detail ( yay time to listen to me blabber ) i made 2 graphics ( one for each wall ) and saved them ass wall1 and wall2 i left space in between each one as the part the mouse will navigate through. so im assuming i want to call out those 2 walls as variables

var wall1:Shape = new Shape; should i calssify them as a shape or sprite?
var wall2:Shape = new Shape;

then i want to add an evet listenr to listen if the mouse is touching either of the walls

wall1.addEventListener(MouseEvent.MOUSE_OVER, resetmouse);
wall2.addEventListener(MouseEvent.MOUSE_OVER, resetmouse);

then make the function to reset the mouse

function resetmouse(event:MouseEvent) :void {

now what would i put here to reset the mouse back to the starting point
and what would i put to specify a starting point for the mouse to bet set at at the start of the app
}

hopefully at least part of that is semi right and makes sense

hoolagon
12-28-2009, 10:02 PM
You cant add MouseOver events to Shapes. You need to use a Sprite

flips30240
12-28-2009, 10:15 PM
so hopefuly
var wall1:sprite = new sprite;

should work? much thanks =)


so far i have


import flash.ui.Mouse;
var wall1:Sprite = new Sprite;
var wall2:Sprite = new Sprite;

wall1.addEventListener(MouseEvent.MOUSE_OVER, resetmouse);
wall2.addEventListener(MouseEvent.MOUSE_OVER, resetmouse);

function resetmouse(event:MouseEvent) :void {

Mouse.hide();
}

im nt getting any script errors but nothing is happening either -_-

hoolagon
12-28-2009, 10:56 PM
are you adding your Sprite to the stage?
Also instead of Mouse.hide() for now just try a trace such as trace("resetmouse");

flips30240
12-28-2009, 11:06 PM
ohh no i didnt add it to the stage, how do i go about doing that? stage.addSprite(wall1); ?

flashGeneral
12-29-2009, 12:03 AM
Try

addChild(wall1);

flips30240
12-29-2009, 12:58 AM
ok so i went witha dif approach


import flash.ui.Mouse;

wall.addEventListener(MouseEvent.MOUSE_OVER, resetmouse);
wall0.addEventListener(MouseEvent.MOUSE_OVER, resetmouse);


function resetmouse(event:MouseEvent) :void {

Mouse.hide();
messagebox.text = "Try Again!";
}

wall.addEventListener(MouseEvent.MOUSE_OUT, mouseout);
wall0.addEventListener(MouseEvent.MOUSE_OUT, mouseout);

function mouseout(event:MouseEvent) :void {

Mouse.show();

}

finish.addEventListener(MouseEvent.MOUSE_OVER, finishfun);

function finishfun(event:MouseEvent) :void {

messagebox.text = "Good Job!";
}


now all i need is instead of mouse.hide and mouse.show i want the mouse to be moved to the start of the maze ( i dont know the coordinates yet ( ill get em later)) what function would i use to do that?

flips30240
12-29-2009, 02:54 AM
just wanted to mark this thread as closed =D finally got what i wanted. Want to say MUCH THANKS to everyone who helped =D

i attached the finished product, not super amazing but you guys helped it come to be =D it has the flash file and .swf

hoolagon
12-29-2009, 07:59 AM
good job