Really depends upon what you mean by this. People often confuse onMouseDown/onMouseUp with onPress/onRelease. The mouse versions just listen for the mouse going down and up, whereas onPress/onRelease check to see if the mouse has been clicked up/down ON a specific movieclip or button.
So, make two movieclips called myClip0 and myClip1
trace(this._name+" was pressed.");
trace("The mouse goes down and "+this._name+" knows it.");
And you will see how the traces are different depending upon if you click down on one of the clips or not. So hopefully that may answer any first bit of your question. I'm going to assume that you want the onMouseDown. So just do what you want to happen:
//do what you want;
//stop what you want
Now you might want something to happen continuously while the mouse is down. Not sure what that might be, but you could use an onEnterFrame, then your functions might look like this:
trace("I'm doing something over and over until you let go!");
So try that out and come back if you have questions.
I didn't know about onPress, but I suppose it could work. I just want something to appear when the mouse button is pressed, and when it is released for a series of things to happen, but I think I have the release part down
When I tried the code, I got many errors saying how it needed to be with an "on handler"
But if onPress would work, I'd like to try that
1 person found this helpful
You are trying to put code directly onto the items you are selecting. Don't do that. That is an old style of coding that went out of favor in 2001 with the introduction of Flash 6. Here is a really good blog article about the difference and why the old way isn't so great:
The code I'm showing you should be placed on the main timeline.
Do you care if the mouse button is pressed when the pointer is on top of a specific movieclip or when the mouse button is pressed regardless of where the pointer is? The first one you want onMouseDown and the second one you want onPress.
The main timeline = the layer that the button is on?
EDIT: It has to be pressed at that specific movieclip, not just anywhere
Yes the same timeline that the "button" is on. So in that case then you would want to use onPress not onMouseDown.
When you say "button" do you mean an actual button instance? Very few people I know actually use buttons. There are some funky strange things about buttons and how they work and what scope they are in. And if you need some movieclip inside a button you won't be able to reference it. So there are so many things that are just odd/inconvenient with them. Most folks I know stopped using them with Flash 6 when you could start adding mouse events to movieclips.
Yes, I am using an actual button for the sole reason that it made sense in my head that if I was making a button, I should make it a button, and not a movieclip
Anyways, if you say that I should use a movieclip I will. This button is essentially a start button, but something is displayed onPress, and the game does not start until onRelease...
How would I go about using onPress? The same as onRelease?
Yeah just like in the examples I showed above.
BTW, you might also want to do something with onReleaseOutside as well...
If you haven't figured out how all this works, I recommend to put aside your current project and make a new file with just a couple simple parts so you can see how it all works without the added complications. Then once you get a handle on it, move it into your project.
Instead of fussing around with layers, buttons, etc. I put the code in my main character's class. I figured it would be easier because I can understand and prevent errors more there (I'm more comfortable putting stuff there-)
I did something like this:
_root.startButton.onPress = function()
_root.supriseMessage._visible = true;
_root.startButton.onRelease = function()
_root.supriseMessage._visible = false;
// I also made everything else false or true in correspondence of how the game needed things to be to run properly
Thanks though, I would have spent much time researching mouseDown only to figure out it doesn't work for my case
If it works for you then great. There are a lot of things about this that aren't best practices and will make things more difficult for you down the line.
Generally you shouldn't use absolute paths from _root. It will make problems if you later load swfs into other swfs.
Also it isn't good practice to use anonymous functions. Notice how your functions in your event handler assignments don't have names. That makes it impossible to reuse them. So:
// do something
will take you down the path toward better coding.
Also you might want to look into onReleaseOutside. If you press the mouse down on startButton, but then move the pointer outside of the button and release you probably won't like what you see.
These are all just suggestions from a lot of years and a lot of mistakes....