Solved

Flash - loop

Posted on 2011-03-22
3
286 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

786 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