Solved

Flash - loop

Posted on 2011-03-22
3
284 Views
Last Modified: 2012-05-11
I've got
ButtonOne.addEventListener(MouseEvent.MOUSE_OVER,ButtonOneOver);

Open in new window


The problem is that I need 6 of the same, only the "ButtonOne and ButtonOneOver" need to change to ButtonTwo and ButtonTwoOver and so on..

please help :)

0
Comment
Question by:ErnstJacobs
3 Comments
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35192199
Try this:
for( var i:int=6; i<6; i++){
     var buttonName:String = "ButtonOne";
     var button:* = getChildByName( buttonName );
     var functionName:String = buttonName.concat("Over");
     button.addEventListener(MouseEvent.MOUSE_OVER, this[functionName]);
}

Open in new window


Warm Regards
Deepanjan Das
0
 
LVL 1

Accepted Solution

by:
smabudhahir earned 500 total points
ID: 35192259
You can have two approaches to this.

1. Name the buttons and functions with numbers starting from 0 to 'n'. Like,
      Button0, Button1, Button2.... and Button1Over, Button2Over.....
    for(var i:Number=0;i<6;i++){
	var fnName:Function = this["Button"+i+"Over"];
	this["Button"+i].addEventListener(MouseEvent.MOUSE_OVER,fnName);
   }

Open in new window



2. Put names to an array.
var buttons:Array = ["ButtonOne","ButtonTwo","ButtonThree","ButtonFour","ButtonFive","ButtonSix"];

for(var i:Number=0;i<6;i++){
	var fnName:Function = this[buttons[i]+"Over"];
	this[buttons[i]].addEventListener(MouseEvent.MOUSE_OVER,fnName);
}

Open in new window

0
 

Author Closing Comment

by:ErnstJacobs
ID: 35192918
Got yours working, it was pretty easy :) Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error 2032 in all the browser 6 2,818
How to convert pdf file to html file 8 388
Consuming WCF in Action Script 3 [ flash Develop ] 3 293
bandwidth 5 67
I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now