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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

movie clips 1

Status
Not open for further replies.

tziviak

Technical User
Oct 10, 2002
128
0
0
US
I have many movieclips -I have 10 movieclips for each type-and i have around 7 types of movie clips (ex. 10 red squares, 10 green triangles, 10 blue circles movieclips) now I want a different action to occur if any of the movieclips get clicked-but the same action should occur if the same type gets clicked (ex. if the user clicks on any of the blue circle-it should get dragged, if they click on any of the green triagles-it should get deleted and so on)

what's an efficient way of doing it except for
if square1.onclick=square2.onlick=function()...

if triangle1.onclick=triangle2.onlick=function()...


there's a prototype-but that affects all the movieclips-is there a way for me to make each of the movie clips-sort of a different category (object) so that way I can use prototype keyword-or anything else-to have the same affect? and not have to write repetitious code? (maybe some sort of inheritence to movieclip)

thank you

if you need any additional info-let me know
 
A) Very keen to see the 'onlick' event that you propose become a reality - maybe version 8 will be 'Porn MX for touch screens' [LOL] (only kidding: my typing sucks too)

B) How about using prototype like you say but having a condition in the method that reads the clip's name and substrings it - if the substring is 'circle' it fires one action, if it's 'square' another etc...

Here's the idea working on the first letter of each clip:

Code:
MovieClip.prototype.onRelease = function() {
	type = this._name.substring(0, 1);
	switch (type) {
	case 'c' :
		//doStuff
		break;
	case 't' :
		//doStuff
		break;
	default :
		//doStuff
	}
};

 
thanks i'll try it-but what is the substring function return the first character -and what 2 numbers do you pass to it?
thank you
 
With 'substring' you pass it the character where you want the cut to start and the length of string you want to return - so (0,1) means start at the first character and cut exactly one character out (strings are zero indexed so the first char is char '0' etc...)

You could also use 'charAt' for a similar effect but 'substring' allows you to check for whole words if you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top