# Functions in duplicate Movieclips

**URL:** <https://forum.kirupa.com/t/functions-in-duplicate-movieclips/257073>\
**Category:** flash\
**Created:** [April 10, 2008, 12:03am UTC](https://forum.kirupa.com/t/functions-in-duplicate-movieclips/257073 "2008-04-10T00:03:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![youwh](https://avatars.discourse-cdn.com/v4/letter/y/82dd89/32.png) [@youwh](https://forum.kirupa.com/u/youwh)\
**Post date:** [April 10, 2008, 12:03am UTC](https://forum.kirupa.com/t/functions-in-duplicate-movieclips/257073/1 "2008-04-10T00:03:46Z")

</div>

I’m currently doing my project thingy, and encounter some difficulties. Hope there is someone who could help me, or guide me. Thanx!

I will have 5 type of buttons. Each type I will duplicate (+1) at some condition.  
Each button is sharing a same functions, just some difference in _value_ and _positions_.

Button type’s name:bug1, bug5, bug10, bug20, bug50

```auto

function dupBug(target:MovieClip, xpos:Number, ypos:Number) {
    i++;
    target.duplicateMovieClip(target+i,i,this.getNextHighestDepth());
    this[target+i]._x = xpos;
    this[target+i]._y = ypos;

    //target.duplicateMovieClip(i,i,{_x:520, _y:380});

}

dupBug(bug1,500,350);
dupBug(bug5,300,350);

```

This code, I’m trying to have a short list of changes on: MovieClip, x position, y position.  
\*\*Q1.\*\*But some how it only reads 1 line of the code, and the position is not right.  
\*\*Q2. \*\*I wanted it to +1 every time I do a action, but it would only add up to maximum of 1, and the duplicated button is not functional. Am I doing something wrong here?

```auto

**bug1**.onRelease = function() {
	this.stopDrag();
	if ((eval(this._droptarget) == bulb) && (bulbx == "on")) {
		_root.total = _root.total+point1;
		this._x = bulb._x;
		this._y = bulb._y;
		this.count = "yes";
		bulbx = "off";
		dupBug(this);
	} else if ((eval(this._droptarget) == bg_remove) && (this.count == "yes")) {
		_root.total = _root.total-point1;
		this.gotoAndPlay(2);
		dupBug(this);
		this.count = "no";
		bulbx = "on";
	} else if ((eval(this._droptarget) == bg_remove) && (this.count == "no")) {
		this.gotoAndPlay(2);
		dupBug(this);
	} else {
		this.gotoAndPlay(2);
		dupBug(this);
	}
};

```

The script here basically implement to every buttons that is duplicated.  
I’m still trying to make everything into another function so I could share / manage it easily between all 5 buttons.

\*\*Q1. \*\*Currently I’m using the exact Instants Name. So its not very convenient if I have a duplicated button of _bug1_ . How could I change it accordingly?

Its much more easier if you download my [fla](http://artificialdesign.com.my/bug.zip) and have a look, so you would know what I am trying to achieve here.

Thanx for any help!
