Be a Supporter!

Mouse.down Event Not Working?

  • 479 Views
  • 8 Replies
New Topic Respond to this Topic
Rational-Delirium
Rational-Delirium
  • Member since: Mar. 21, 2007
  • Offline.
Forum Stats
Supporter
Level 15
Melancholy
Mouse.down Event Not Working? 2012-12-17 00:13:05 Reply

I'm not sure how to make a MOUSE.DOWN event work, could you please help?

package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class Main extends MovieClip {
		
		public function Main() {
			addEventListener(MouseEvent.MOUSE_DOWN, mouseClick);
		}
		public function mouseClick(e:MouseEvent) {
			trace("HELLO");
		}
	}
}

You can't know what you don't know if you can only use yourself as a reference point.

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to Mouse.down Event Not Working? 2012-12-17 01:25:12 Reply

You need to add the mouse event on something.

If you do:

myButton.addEventListener(MouseEvent.MOUSE_DOWN,mouseClick);

Then when you click on that button, it will fire the mouse event. If you just want to click anywhere on the stage, add the mouse event to the stage:

stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseClick);
Rational-Delirium
Rational-Delirium
  • Member since: Mar. 21, 2007
  • Offline.
Forum Stats
Supporter
Level 15
Melancholy
Response to Mouse.down Event Not Working? 2012-12-17 11:19:20 Reply

Hey, thanks! I had no idea stage would do anything, but all of the tutorials made it target a button, so I knew something was missing. AS3 is looking quite new compared to AS2, but I personally like the class system.


You can't know what you don't know if you can only use yourself as a reference point.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Mouse.down Event Not Working? 2012-12-17 11:31:34 Reply

At 12/17/12 11:19 AM, Rational-Delirium wrote: Hey, thanks! I had no idea stage would do anything, but all of the tutorials made it target a button, so I knew something was missing. AS3 is looking quite new compared to AS2, but I personally like the class system.

stage is whatever you set it to, but defaults to Sprite(FlashDevelop) or MovieClip(Flash IDE)
set events that require focus to the stage (one of the rare use-cases for it)

AS2 uses the class system, as well. It's just that it doesn't force devs to use it like AS3 does, so 99% of AS2 coders go the AS1 route with it.
Also, compared to AS3, AS2's OOP structure sucks. There's so few classes for anything you can't really do much with it without it becoming bloated because of all the base classes.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
Rational-Delirium
Rational-Delirium
  • Member since: Mar. 21, 2007
  • Offline.
Forum Stats
Supporter
Level 15
Melancholy
Response to Mouse.down Event Not Working? 2012-12-17 11:42:54 Reply

I don't understand what you mean by 'stage is whatever you set it to.' My main class extends to Movieclip, but do you mean that I could make it extend to Movieclip or Sprite?


You can't know what you don't know if you can only use yourself as a reference point.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Mouse.down Event Not Working? 2012-12-17 11:48:59 Reply

At 12/17/12 11:42 AM, Rational-Delirium wrote: I don't understand what you mean by 'stage is whatever you set it to.' My main class extends to Movieclip, but do you mean that I could make it extend to Movieclip or Sprite?

I would highly recommend extending Sprite, as we programmers have no use for frames. They just get in our way most of the time.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Mouse.down Event Not Working? 2012-12-17 12:11:40 Reply

At 12/17/12 11:31 AM, egg82 wrote: stage is whatever you set it to, but defaults to Sprite(FlashDevelop) or MovieClip(Flash IDE)
set events that require focus to the stage (one of the rare use-cases for it)

stage is a read only property of type Stage and hence cannot be set.

Rational-Delirium
Rational-Delirium
  • Member since: Mar. 21, 2007
  • Offline.
Forum Stats
Supporter
Level 15
Melancholy
Response to Mouse.down Event Not Working? 2012-12-17 12:13:16 Reply

At 12/17/12 11:48 AM, egg82 wrote:
At 12/17/12 11:42 AM, Rational-Delirium wrote: I don't understand what you mean by 'stage is whatever you set it to.' My main class extends to Movieclip, but do you mean that I could make it extend to Movieclip or Sprite?
I would highly recommend extending Sprite, as we programmers have no use for frames. They just get in our way most of the time.

I remember the AS3 Bible saying it was more efficient, but I thought it'd be simpler to stick to the tutorial standards of the internet at the beginning :P I just switched everything to extend Sprite, but I don't know what you mean by stage being what you set it too. Do you mean that

stage.randomSprite

references the bounding box of a Sprite, while

stage

references the bounding box of the stage?


You can't know what you don't know if you can only use yourself as a reference point.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Mouse.down Event Not Working? 2012-12-17 12:13:51 Reply

At 12/17/12 12:11 PM, milchreis wrote: stage is a read only property of type Stage and hence cannot be set.

fair enough, I suppose I shouldn't have said "stage" - think of Main as the timeline, or root


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature