00:00
00:00
Newgrounds Background Image Theme

Someone gifted Speedo supporter status!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS3 buttonDown not working? *Bump*

411 Views | 3 Replies
New Topic Respond to this Topic

I posted the wrong code last thread. For some reason I can't get the buttonDown property to work?

is it anything to do with the fact all this code is within a movie clip?

import flash.events.Event;

stop();

playScreen_clickButtonMovieClipUp.addEventListener(Event.ENTER_FRAME, playScreen_clickButton_stateChangeEventUp);

function playScreen_clickButton_stateChangeEventUp(event:Event){
	
	if (playScreen_clickButtonMovieClipUp.buttonDown === true){
		gotoAndStop(2);
	}
}

Response to AS3 buttonDown not working? *Bump* 2015-02-23 14:38:22


Why don't you just listen for the mouse down event rather than the enter frame? I've never seen the buttonDown property before, it may not be exactly what you think it is. For instance, because you're using strict equality "===", if that property actually returned an int (for whatever reason...):

1 === true // Evaluates to false
1 == true // In some languages, will evaluate to true

While I'm not sure this is the case in AS3, it shows that "===" doesn't do any conversion while "==" does.

Anyway, if you listen for the mouse down, it would look something like this:

myThing.addEventListener(MouseEvent.MOUSE_DOWN, myFunction)

function myFunction(e:MouseEvent)
{
    trace("myThing clicked");
}

the buttonDown seems to be a ComponentEvent and needs the componentEvent library as far as i understand, and that would force you into using ComponentEvents (whatever they are). If you dont want to do it the normal way you could have a boolean var be made == to true/false from a MouseEvent.MOUSE_DOWN and/or use a MouseEvent.MOUSE_UP to change it back. If that makes sense if not ill clarify.

Dont forget to import the correct library (Event/MouseEvent/ComponetEvent...);

Response to AS3 buttonDown not working? *Bump* 2015-02-24 16:00:36


At 2/23/15 02:38 PM, Sam wrote: Why don't you just listen for the mouse down event rather than the enter frame? I've never seen the buttonDown property before, it may not be exactly what you think it is. For instance, because you're using strict equality "===", if that property actually returned an int (for whatever reason...):

Thanks. I used MOUSE_UP and MOUSE_DOWN like you said and it worked perfectly :D You could say you helped me seal the deal...