473,387 Members | 3,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1902
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

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

Similar topics

8
by: David Hitillambeau | last post by:
Hi guys, As I am new to Python, i was wondering how to declare and use global variables. Suppose i have the following structure in the same module (same file): def foo: <instructions>...
1
by: Andr? Roberge | last post by:
I have the following two files: #--testexec.py-- def exec_code(co): try: exec co except: print "error" #-- test.py--
7
by: Lyn | last post by:
Hi and Season's Greetings to all. I have a question regarding the use of a qualifier word "Global". I cannot find any reference to this in Access help, nor in books or on the Internet. "Global"...
33
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have...
10
by: David P. Donahue | last post by:
When I wrote websites in VB .NET, I would often put functions in Global for all the pages to call. Now, in C#, doing so results in "references to non-static objects" and whatnot. I realize what...
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
3
by: User1014 | last post by:
A global variable is really just a property of the "Global Object", so what does that make a function defined in the global context? A method of the Global Object? ...
8
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project...
15
by: =?Utf-8?B?UGF0Qg==?= | last post by:
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax code file. In 1.1 I could have a code behind file for the global.asax file. This allow for shared variables of the...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.