Solved

Flash - loop

Posted on 2011-03-22
3
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
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,…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

730 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