I probably just dont understand something but...(solved)

7 posts

Flag Post

Why would this work


if (Key.isDown(78))
			{

				if (nreleased)
				{

					nreleased = false;
                                        //whatever I want to happen

and this doesnt?


mainMenu.roundpicker.addEventListener("mouseDown", chooseround);

function chooseround(e:Event)
		{
			
			if (clickreleased)
			{
				clickreleased = false;
                                //whatever I want to do

Im sure its probably just due to me not understanding something thats a basic thing with the "mouseDown", but I dont know whatever that basic thing is.

 
Flag Post

It could be that “mouseDown” should instead be “mouse down”, or “MouseDown”, or any other variation thereof, which is why you should replace that with flash.Events.MouseEvent.MOUSE_DOWN as a first step.

Then there’s the question of whether the element you put this event listener on is actually able to dispatch mouse events. Simplest way to check: stick a trace at the beginning of your function and verify that the listener actually triggers.

Finally, there’s your clickreleased variable, for which you gave us no context. Is it even a Boolean, initialized, and set to true? I’d check, and stick a second trace in there for good measure.

 
Flag Post

The clickreleased variable is a boolean set to false, just like it is in nreleased.


function chooseround(e:Event)
		{
			trace("called chooseround function");
			if (clickreleased)
			{
            trace("called if clickreleased");

called chooseround function traces, but called if clickreleased doesnt.

I did your change for Mouse_Down and that gave me some progress. Ill post the whole function so you can get a better idea of whats happening.


function chooseround(e:Event)
{
	trace("called chooseround function");
	if (clickreleased)
	{
		trace("called if clickreleased");
		clickreleased = false;
		if (mainMenu.roundpicker.currentFrame == 6)
		{
			trace("round-1");
			ship.roundnumberchosen = 1;
			mainMenu.roundpicker.gotoAndStop(7);
		}
		if (mainMenu.roundpicker.currentFrame == 7)
		{
			trace("round-3");
			ship.roundnumberchosen = 3;
			mainMenu.roundpicker.gotoAndStop(6);
		}
	}
	else
	{
		clickreleased = true;

	}
}

and it triggers both round-1 and round-3 which is what the clickreleased is suppose to prevent.

as a comparison to where I have a similar function working as intended.


if (Key.isDown(77))
			{
				if (mreleased)
				{
					togglemusic();
					mute1 = ! mute1;
					this.nextFrame();
				}
				mreleased = false;
			}
			else
			{
				mreleased = true;

			}

Its suppose to make it so that whatever I call only happens once. on a single button press, instead of possibly calling it 4 or 5 times on 1 button press. I was thinking I could translate that into mouse presses, but for some reason (and its probably some basic reason) its not happening.

 
Flag Post

Every time the following two conditions are met:

The mouse pointer is over the element.
The user presses the mouse button (and I mean presses, not holds down)

the element dispatches a MouseEvent.MOUSE_DOWN. If the mouse pointer is not over the element (or one of its children on the display list, mouse events bubble) or if the mouse button is already being held down when the pointer comes over the element, the event will not fire. Also, and in this the mouse differs from the keyboard, holding the mouse button down for an extended period of time will not cause the event to fire repeatedly.

I’m not sure what you’re trying to do with:

the clickreleased variable. Right now if nothing else changes the value of clickreleased I’d expect only every other click to do anything (one click sets clickreleased to true, the next one resets it to false and performs the extra tests).

the MovieClip gymnastics. However I’d respectfully point out that if currentFrame == 6 you change it to 7 (gotoAndStop(7)) then check if it is equal to 7 and set it back to 6. ship.roundnumberchosen will be 3 at the end of the process, as the value gets overwritten. You might want to change the second conditional from ‘if’ to ‘else if’ so only one conditional is executed each pass.

 
Flag Post

Sigh youre right. I was just making it too complicated. I dont know why I didnt just use else if. I am using it the function liteally right before it. Thank you.

Btw I edited my post (probably while you were typing) to clarify what the function was doing. It works using the simple else if though. I was misunderstanding what was happening. I thought that since it was changing the currentround right back that it was because of it being held. Something basic like that caused me to go completely off track. Oh well, learn something new everyday.

 
Flag Post

Yea I saw the edit after I posted, and it clarifies why you put the clickreleased in there at all. It was unnecessary. I trust things are working as you hoped now?

 
Flag Post

Yes they are, thank you :)