Solved

Flash - loop

Posted on 2011-03-22
3
282 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
Comment Utility
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
Comment Utility
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
Comment Utility
Got yours working, it was pretty easy :) Thank you
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
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.

771 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

12 Experts available now in Live!

Get 1:1 Help Now