469,357 Members | 1,857 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,357 developers. It's quick & easy.

Global MouseEvents...

rrocket
116 100+
Is there a way to encompass all buttons/movie clips in the rollover function instead of writing them out for everyone you plan to use on a page?

Something like this:
Expand|Select|Wrap|Line Numbers
  1. AvailableLoads_mc.addEventListener(MouseEvent.ROLL_OVER, TabRollOver);
  2. function TabRollOver(event:MouseEvent):void {
  3.     this.name.alpha = .5;
  4. }
  5. AvailableLoads_mc.addEventListener(MouseEvent.ROLL_OUT,TabRollOut);
  6. function TabRollOut(event:MouseEvent):void {
  7.     this.alpha = 1;
  8.     }
Instead of having to do it this way:
Expand|Select|Wrap|Line Numbers
  1. AvailableLoads_mc.addEventListener(MouseEvent.ROLL_OVER, TabRollOver);
  2. function TabRollOver(event:MouseEvent):void {
  3.         AvailableLoads_mc.alpha = .5;
  4.  
  5.  
  6. }
  7. AvailableLoads_mc.addEventListener(MouseEvent.ROLL_OUT,TabRollOut);
  8. function TabRollOut(event:MouseEvent):void {
  9.         AvailableLoads_mc.alpha = 1;
  10. }
In that case I would only have to write out the initial line to call the function instead of recreating functions for each individual part even if they all do the same thing.
Oct 31 '07 #1
3 1655
xNephilimx
213 Expert 100+
Hi rrocket.
What you can do is name the buttons with a prefix name and a correlative number, so you can add the event listeners with a for, like this:

Expand|Select|Wrap|Line Numbers
  1. /*
  2. suppose you have the buttons b1, b2, b3 and b4
  3. */
  4.  
  5. for(var i:uint = 1; i < 5; i++) {
  6.     var b:DisplayObject = this.getChildByName('b'+i);
  7.     b.addEventListener(MouseEvent.ROLL_OVER, onRollOver);
  8.     b.addEventListener(MouseEvent.ROLL_OUT, onRollOut);
  9. }
  10.  
  11. function onRollOver(e:MouseEvent):void {
  12.     e.target.alpha = 0.5;
  13. }
  14.  
  15. function onRollOut(e:MouseEvent):void {
  16.     e.target.alpha = 1;
  17. }
  18.  
  19.  
As you can see, the event holds it's target (that in this case is the button that recieved the event) so you can access the event's current target by e.target then access any property or method the target has.

Best regards,
The_Nephilim

Is there a way to encompass all buttons/movie clips in the rollover function instead of writing them out for everyone you plan to use on a page?

Something like this:
Expand|Select|Wrap|Line Numbers
  1. AvailableLoads_mc.addEventListener(MouseEvent.ROLL_OVER, TabRollOver);
  2. function TabRollOver(event:MouseEvent):void {
  3.     this.name.alpha = .5;
  4. }
  5. AvailableLoads_mc.addEventListener(MouseEvent.ROLL_OUT,TabRollOut);
  6. function TabRollOut(event:MouseEvent):void {
  7.     this.alpha = 1;
  8.     }
Instead of having to do it this way:
Expand|Select|Wrap|Line Numbers
  1. AvailableLoads_mc.addEventListener(MouseEvent.ROLL_OVER, TabRollOver);
  2. function TabRollOver(event:MouseEvent):void {
  3.         AvailableLoads_mc.alpha = .5;
  4.  
  5.  
  6. }
  7. AvailableLoads_mc.addEventListener(MouseEvent.ROLL_OUT,TabRollOut);
  8. function TabRollOut(event:MouseEvent):void {
  9.         AvailableLoads_mc.alpha = 1;
  10. }
In that case I would only have to write out the initial line to call the function instead of recreating functions for each individual part even if they all do the same thing.
Nov 2 '07 #2
rsdev
149 100+
Hi,

I would write a class that extends the MovieClip class then in the library for each movieclip that you want to use the function tick to enable runtime actionscript and enter the path to your class.

here's an example:

class as.MyMovieClipClass extends MovieClip
{
//write your functions here
}

then in the movieclip linkage - as.MyMovieClipClass

Then save the class in the source directory in a folder named "as".

This is how I work in AS 2.0 to create OOP app's.
Nov 4 '07 #3
xNephilimx
213 Expert 100+
That's a good one too. But it's more suitable for a big app, and extending with really usable and cool features, all depends on the project.
In AS3 though it's a little difference, but I don't know about flash, I just use AS3 with Flex, and flash tends to ease things a little when coming to this kind of stuff.

Best regards,
The_Nephilim

Hi,

I would write a class that extends the MovieClip class then in the library for each movieclip that you want to use the function tick to enable runtime actionscript and enter the path to your class.

here's an example:

class as.MyMovieClipClass extends MovieClip
{
//write your functions here
}

then in the movieclip linkage - as.MyMovieClipClass

Then save the class in the source directory in a folder named "as".

This is how I work in AS 2.0 to create OOP app's.
Nov 4 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by David Hitillambeau | last post: by
1 post views Thread by Andr? Roberge | last post: by
10 posts views Thread by David P. Donahue | last post: by
8 posts views Thread by Rob T | last post: by
15 posts views Thread by =?Utf-8?B?UGF0Qg==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.