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]
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
Also, please use [AS][/AS] tags and format the code correctly as it’s easier to read. Thanks.
And finally, welcome to kirupa forum.
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?
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
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]
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]