functions in array

Hey guys, is het possible to put the following in a loop so I have less lines of code? Because I need to do the following times 10.

function anchor10_Over(e:MouseEvent){
	anchor10.play();
}
function anchor11_Over(e:MouseEvent){
	anchor11.play();
}
function anchor12_Over(e:MouseEvent){
	anchor12.play();
}

Open in new window

ErnstJacobsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Antonio EstradaTech Leader / Senior Web DeveloperCommented:
Try

anchor10.addEventListener(MouseEvent.MOUSE_OVER, anchor_Over);
anchor11.addEventListener(MouseEvent.MOUSE_OVER, anchor_Over);
anchor12.addEventListener(MouseEvent.MOUSE_OVER, anchor_Over);
//etc, or this could be a for loop

function anchor_Over(e:MouseEvent) {
   e.currentTarget.play();
}

Open in new window


Good luck,

-V

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dgofmanCommented:
Optimization of Vulturous script

for(var i:uint = 0; i < 15; i++){
    this["anchor" + i ].addEventListener(MouseEvent.MOUSE_OVER, function(e:MouseEvent) {
         e.currentTarget.play();
     });
}
ErnstJacobsAuthor Commented:
Hey guys, I''ve got a little problem with that code, which is a conflict with earlier written code, I didnt show so thats my fault...

for(var i = 0; i < anchors.length; i++){
	var overName:Function = this[anchors[i]+"_Over"];
	var outName:Function = this[anchors[i]+"_Out"];
	var upName:Function = this[anchors[i]+"_Up"];
	this[anchors[i]].addEventListener(MouseEvent.MOUSE_OVER,overName);
	this[anchors[i]].addEventListener(MouseEvent.MOUSE_OUT,outName);	
	this[anchors[i]].addEventListener(MouseEvent.MOUSE_UP,upName);
}

Open in new window


And when I use your code, it gives a conflict. Ofcourse because the eventhandler is already there but I dont know how to change it so it works.
ErnstJacobsAuthor Commented:
Nevermind,. got it working! Great, thanks
Antonio EstradaTech Leader / Senior Web DeveloperCommented:
Glad to help :)

-V
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.