Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

event for array of movieclips

Status
Not open for further replies.

tziviak

Technical User
Oct 10, 2002
128
US
I have an array of movieclips-and I want to set an onclick action to each of them (the same action) is there a shorter way to do it than array[0].onClick=array[1].onClick=...=function(){}?
maybe some kind of loop?
 
for(var i =0;i<myarray.length;i++){
myarray.onRelease = function(){
//do something
}
}
 
Already forgot how to post that type of code, hey Bill?
Nor do you bother to preview your posts!

See when you use , it italicizes the rest of your post!
Get it?

So either use the code tags, or uncheck Process TGML at the bottom of the post window, that is, if you can find it!

Was the fishing out of Shad Bay as good today, as it was yesterday?

Regards,

cubalibre2.gif

[bigcheeks] I'm Bill Watson's biggest fan!
[bigcheeks]
 
HI, the problem is that later on in the code-I want to use &quot;i&quot; and it is always set to 10-because it loops til the end every time-any clue?
also I have a few arrays-so what I'd like to do is something to this affect array.onClick=array2.onClick...=function() {//code}
-let me know if you need more explicit code
thank you
 
Code:
for(var i = 0; i < myarray.length; i++){
    myarray[i].onRelease = function(){
        //code...
    };
}

Regards,

cubalibre2.gif

[bigcheeks] I'm Bill Watson's biggest fan!
[bigcheeks]
 
do you mean something like this

Code:
one = [&quot;me&quot;,&quot;you&quot;,&quot;them&quot;]
two = [&quot;us&quot;,&quot;him&quot;]
three = [&quot;go&quot;,&quot;back&quot;,&quot;now&quot;]
four = [one,two,three]
for( var i = 0;i<four.length;i++){
	for(a in four[i]){
		four[i][a].onRelease = function(){
                 //do something
                 }
	}
}

the use of i dont matter if its declared locally as var. wont affect i anywhere else. could be any letter of course.

Note the clever use of code brackets
 
this is what I did to begin with (I realized the mistake-here is my code:

for (var i=0; i<line33.length; i++)
{
if (line33.onPress)
break;
}
line33.onPress =frame81.onPress=frame69.onPress = frame47.onPress = frame33.onPress = Line81A.onPress = Line69A.onPress = Line47A.onPress = function ()
{
selected = this;
this.startDrag();
};


it worked-when I put this whole code into the for loop-but by the onRelease event (which is much more complex-and needs to keep on refrencing the the object-ex. line33-i is always set to 10-
I'm sure there is a better way to do it-any ideas?
 
oops-I did the same mistake myself.

billWatson-thanks=but it's not an array within an array-I just have many arrays of movieclips and many single movieclips-and they all basically should perform the same action-so I'm looking for a short way to reference my arrays instead of
arr1[0].onclick=arr1[1].onClick=arr2[0].onClick=object3.onClick=object4.onClick....

 
what i gave you was an array of arrays. if you put all your arrays in one array as above then the code i posted will work fine
 
or even simpler as long as you want this done to every movieclip in your movie

MovieClip.prototype.onRelease = function(){
//do something
}
 
wow! that's powerful-and saves so much code (the mc.prototype...)

just one more little problem-now in the onrelease function I have if statements-if it's object1-do this, if it's any element of array5 do something else-so what's my best (and least code )way to do it
ex.
else if (this==Line69[0] || this==Line69[1] || this==Line69[2]...){//code}

thanks-if you can help me with this-then I'll be basically done-can't wait...
 
The clerverness is in remembering to use them, and not in the use of the code tags itself!
But don't worry, I'll be around next time you forget!
After that we can slowly try to get you back in using proper punctuation... And after that... Who knows, we may even turn you into an artist!

Regards,

cubalibre2.gif

[bigcheeks] I'm Bill Watson's biggest fan!
[bigcheeks]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top