# Help with if, else

**URL:** https://forum.kirupa.com/t/help-with-if-else/28366
**Category:** Uncategorized
**Created:** [August 13, 2003, 12:50am UTC](https://forum.kirupa.com/t/help-with-if-else/28366 "2003-08-13T00:50:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![smiddy](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@smiddy](https://forum.kirupa.com/u/smiddy)
#### Post date: [August 13, 2003, 12:50am UTC](https://forum.kirupa.com/t/help-with-if-else/28366/1 "2003-08-13T00:50:00Z")

</div>

im trying to make a drag and drop program that is supposed to be used as a floorplaning thing but i cannot get an if, else statement to work. what i want to happen is if it is the original item it will create a duplicate of it when clicked on but if it is a duplicate of it it will drag and drop. the following is what i have written on the object.  
[AS]on (press) {  
if (name == “chair”) {  
i = i+1;  
duplicateMovieClip(\_root.chair, “chair”+i, i);  
} else {  
startDrag(this);  
}  
}  
on (release) {  
stopDrag();  
}[/AS]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 13, 2003, 1:28am UTC](https://forum.kirupa.com/t/help-with-if-else/28366/2 "2003-08-13T01:28:32Z")

</div>

There’s a little typo…  
[AS]on (press) {  
if ( **\_name** == “chair”) {  
i = i+1;  
duplicateMovieClip(\_root.chair, “chair”+i, i);  
} else {  
startDrag(this);  
}  
}  
on (release) {  
stopDrag();  
}[/AS]  
[http://www.macromedia.com/support/flash/action\_scripts/actionscript\_dictionary/actionscript\_dictionary541.html](http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary541.html)

Also, please use [**AS][**/AS] tags and format the code correctly as it’s easier to read. Thanks.

And finally, welcome to kirupa forum. 😉

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 13, 2003, 4:05am UTC](https://forum.kirupa.com/t/help-with-if-else/28366/3 "2003-08-13T04:05:05Z")

</div>

Ok cool, it works now. I copied the action script for some other objects (wall, desk etc) but whenever i put one in it deletes one of the other objects (eg i put a wall in and then when i go to put a desk in it deletes the wall). How can i fix this?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 13, 2003, 4:10am UTC](https://forum.kirupa.com/t/help-with-if-else/28366/4 "2003-08-13T04:10:13Z")

</div>

its a problem with the depth, it removes one to make room for the other.

to fix it, i recomend creating seperate variables for each object

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 13, 2003, 4:23am UTC](https://forum.kirupa.com/t/help-with-if-else/28366/5 "2003-08-13T04:23:52Z")

</div>

the seperate variables thingy didn’t work  
this is what i wrote for the wall  
[AS]  
on (press)  
{ if (\_name == “wall”)  
{  
x = x + 1;  
duplicateMovieClip (\_root.wall, “wall” + x, x);  
}  
else  
{  
startDrag(this);  
}  
}

on(release)  
{  
stopDrag();  
}  
[/AS]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 13, 2003, 5:04am UTC](https://forum.kirupa.com/t/help-with-if-else/28366/6 "2003-08-13T05:04:46Z")

</div>

Don’t create different variables, you use the same variable instead.  
[AS]on (press) {  
if ( **\_name** == “chair”) {  
\_parent.depth++;  
this.duplicateMovieClip(“chair”+\_parent.depth, \_parent.depth);  
} else {  
this.startDrag();  
}  
}  
on (release) {  
this.stopDrag();  
}  
//  
on (press) {  
if ( **\_name** == “wall”) {  
\_parent.depth++;  
this.duplicateMovieClip(“wall”+\_parent.depth, \_parent.depth);  
} else {  
this.startDrag();  
}  
}  
on (release) {  
this.stopDrag();  
}[/AS]
