PDA

View Full Version : movie clips



tziviak
October 1st, 2003, 07:51 PM
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

kode
October 1st, 2003, 08:30 PM
Welcome, tziviak. :beam:

You can use the for (http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary274.html) action to create a loop and assign the event handlers; assuming the instances are triangle1, triangle2, triangle3, ..., triangle10:

var total = 10;
for (var index = 1; index<=total; index++) {
this["triangle"+index].onPress = function() {
statement(s);
};
}

tziviak
October 1st, 2003, 10:18 PM
Thank you for responding
but at one point in my code-I have an if statement-to check if it's a triangle-do one thing, else if it's a square...
so how would I combine the if and for?

kode
October 1st, 2003, 10:35 PM
for (var index = 1; index<=total; index++) {
this["triangle"+index].onPress = function() {
// this is a triangle, do this
};
this["square"+index].onPress = function() {
// this is a square, do that
};
}
;)

tziviak
October 15th, 2003, 03:06 PM
is there a way to code-that if this triangle+index is selected-then the following code should execute?
because I don't want to have it connected to the onPress event-since it was clicked on already.

here's part of my code: (I'm never getting into the if)

MovieClip.prototype.onRelease=function () {
stopDrag();

//checking if it's the user dropped off the item within the grid
if (this._y < gridStartY or this._x<gridStartX or this._y>gridEndY or this._x > gridEndX) {


for (var ind = 1; ind<=3; ind++) {
trace ("line selected " + this);
if (this==this["TLine"+ind])
{
trace("inside if")
this._x = origLine33X;
this._y = origLine33Y;
this._visible=false;

}
}

thank you