Combination - Copy/Drag&Drop/Delete and MC count

I have looked all around the forum and cannot find a solution to a problem I have.

I was wondering if you could help:

Okay I have a movie clip = circle
When the user clicks the circle I want the user to be able to drag and drop a new instance ie circle1.

This whole process needs to be repeatable…ie next time user clicks the original circle ie circle the code must know the last instance number ie circle1 exists and when the user clicks circle that circle2 is created dragged and dropped…so on and so on.

This is easy you may say - duplicatemovie and startdrag etc…the problem is that when the user clicks on the original circle the mouse focus is on the original circle and not the new instance just created ie circle1 which then needs to be dragged and dropped.

Just to complicate things the user needs to be able to delete a circle at any time by using the keyboard ‘del’ key.

Anyone want to take this on ???

use onMouseUp to detect the release of the dragged duplication and

onKeyDown = function(){
if (Key.isDown(Key.DELETEKEY)){
// …

for deleting

[AS]
function addOne(){
_root.selected=attachMovie(“circle”,“circle”+depth,depth++,{
onPress:selectit, onMouseUp:dropit, _x:_xmouse, _y:_ymouse});
_root.selected.startDrag(true);
}
function selectit(){
_root.selected=this;
this.startDrag(false);
this.onMouseMove=function(){
this.stopDrag();
_root.addOne();
delete this.onMouseMove;
}
}
function dropit(){
this.stopDrag();
delete this.onMouseMove;
}
function onKeyDown(){
if(Key.getCode()==“D”.charCodeAt(0))
_root.selected.removeMovieClip();
}

Key.addListener(this);

depth=0;
addOne();
[/AS]
for some reason i had to use d instead of delete

Hi,

Thank you both for helping out I am new to FlashMX but not a novice and any help is greatly appreciated Clownstaples the file works great…If I just explain myself in a bit more detail could you tweak it.

On movie start a circle needs to be on the stage may be near the top left hand side. This is to act as the template from which ‘all’ new instances of the object are made ie a click drap and drop. (Click,drag and drop instances can only come from the original template instance circle in the top left hand corner not from the duplicated instances - Only one source the original template)

You have done the code to select and then hit ‘d’ to delete that is cool but the first instance ie circle should not be allowed to be deleted. After a new instance of the original template is created and the user wants to delete it could the user just hover over it which reduces the alpha to 50 and include the option to hit ‘d’ to delete. (So that the user does not have to click the new instance and then hit ‘d’ to delete, just hover over and hit ‘d’)

It would be great to have the instance name in the middle of each circle to keep track of things…and even better if there was a dynamic text field at the bottom that kept track of the instance names that were on the stage at any one time (ie if circle, circle1, circle2, circle3 were added then they would show in the text field but if circle2 was to be deleted then it would be removed from the dynamic text field)

Apart from that you have come good with this one…I know it seems at lot to me but to you it may not be a problem.

The ultimate aim is to have the your code and above modifications to be generic/ global so that if for example, I wanted 4 objects circle, triangle, square and rectangle at the start of the movie in top left that no matter which ever object template was clicked, drag and dropped etc the code is generic.

May be given the start of the movie the 4 template objects are put on stage in the top left, then somehow after a mouse press the name of the original object template that is chosen is got somehow:

on (press) {
getproperty(this,_name)
}

which then passes the name ie circle, tri, square or rectangle to the generic function set which does its job and duplicates the template that is clicked and dragged and dropped, but the new instance would still need to be deleted (Remember not the original template cannot be deleted)

Could you do this ???..if so coluld I get a file like last time as I learn quicker from a file ??

Thanks for all your help so far…it has saved me a lot of frustration over the last few weeks.

Out of interest where did you start to learn actionscript, I have the the Flash MX bible as I need to learn flash as well as script…is this a good place to start I need to get up to speed quick.

Speak to you soon.

:thumb:

[AS]
function addOne(){
_root.selected=this.duplicateMovieClip(this._name+depth,depth++);
_root.selected.startDrag(true);
_root.selected.onPress=grabit;
_root.selected.onRollOver=selectit;
_root.selected.onRollOut=deselectit;
_root.selected.onRelease=dropit;
}
function selectit(){
_root.selected=this;
this._alpha=50;
}
function deselectit(){
_root.selected=null;
this._alpha=100;
}
function grabit(){
this.startDrag(false);
}
function dropit(){
this.stopDrag();
}
function onKeyDown(){
if(Key.getCode()==“D”.charCodeAt(0))
_root.selected.removeMovieClip();
}
Key.addListener(this);
depth=0;
circle.onPress=addOne;
triangle.onPress=addOne;
stop();
[/AS]
let me know which lines of code you dont understand. You should be able to finish it off from here.

Thanks for all of this…I am not ungreatful but I need to get all working before I try to really understand the code.

There are a few small amendments:

  1. Each time an object template is clicked at the moment the instance name is incremented regardless of object. If 6 circles are created for example circle6 followed by the first triangle the instance name will be triangle7…it needs to be triangle1

  2. When the template object is clicked to duplicate the instance it is locked to the mouse even if the mouse button is released and only released when a second click is performed…this is not a true drag and drop which it needs to be.

  3. How would I attempt to write the current instance names to a a single dynamic text field ie if one is deleted that it removes it from the text field etc ?

This will be the last time I ask for the file I promise if you can do the above.

Speak to you soon.

[AS]
function addOne(){
_root.selected=this.duplicateMovieClip(this._name+(++this.num),depth++);
_root.selected.startDrag(true);
_root.selected.onPress=grabit;
_root.selected.onRollOver=selectit;
_root.selected.onRollOut=deselectit;
_root.selected.onRelease=dropit;
}
function selectit(){
_root.selected=this;
this._alpha=50;
_root.currentname=this._name;
}
function deselectit(){
_root.selected=null;
this._alpha=100;
}
function grabit(){
this.startDrag(false);
}
function dropit(){
this.stopDrag();
}
function onKeyDown(){
if(Key.getCode()==“D”.charCodeAt(0))
_root.selected.removeMovieClip();
}
function dropnew(){
_root.selected.stopDrag();
}
Key.addListener(this);
depth=0;
circle.onPress=addOne;
circle.onReleaseOutSide=dropnew;
triangle.onPress=addOne;
triangle.onReleaseOutSide=dropnew;
square.onPress=addOne;
square.onReleaseOutSide=dropnew;
stop();
[/AS]
This should do the trick.

Aw, don’t mention it. Just let me know when you are interested in learning a little more about actionscript.

Yo,

Thanks muchly…so so impressed…the dynamic text box needs to do the following:

(I am learning from this by the way not just getting stuff for free…)

  1. Need to track the new instance names as they happen in a serial list in the dyanmic text field = A.

But

  1. If one instance is deleted then the instance name would be remove from the dynamic text field but original form is kept = B

For Example:

Before: Added

A = Circle1, Circle2, Square1, Circle3, Square2, Circle4, Circle5, Square3.

After: Deleted Circle2/Square2/Circle5

B= Circle1, Square1, Circle3, Circle4, Square3.

And so on…could you work your magic just one last time and then I will sit with a cup of tea and really try to understand how it all works…I like your way of doing things…good to learn from someone who is logical.

Bye for now…=)

[AS]function addOne(){
_root.selected=this.duplicateMovieClip(this._name+(++this.num),depth++);
_root.selected.startDrag(true);
_root.selected.onPress=grabit;
_root.selected.onRollOver=selectit;
_root.selected.onRollOut=deselectit;
_root.selected.onRelease=dropit;
_root.names[_root.names.length]=" "+_root.selected._name;
upDate();
}
function selectit(){
_root.selected=this;
this._alpha=50;
}
function deselectit(){
_root.selected=null;
this._alpha=100;
}
function grabit(){
this.startDrag(false);
}
function dropit(){
this.stopDrag();
}
function onKeyDown(){
if(Key.getCode()==“D”.charCodeAt(0) &&
_root.selected!=null)
{
var p=_root.selected._name;
var s = " "+_root.names.toString();
var n = s.indexOf§;
_root.names=(s.substring(1,n)+
s.substring(n+p.length+2,s.length)).split(’,’);
if (n+p.length+2>=s.length)
_root.names.length–;
_root.selected.removeMovieClip();
_root.selected=null;
upDate();
}
}
function dropnew(){
_root.selected.stopDrag();
}
function upDate(){
_root.currentnames=_root.names.toString();
_root.currentnames=_root.currentnames.substring(1,_root.currentnames.length);
}
Key.addListener(this);
depth=0;
names=[];
things=[circle,triangle,square,trapezoid];

for(var i=0;i<things.length;i++) {
things*.onPress=addOne;
things*.onReleaseOutSide=dropnew;
}
stop();[/AS]

*Originally posted by ibex *
**
(I am learning from this by the way not just getting stuff for free…)
**

Good, because you’ll be tested on this at the end of the week!

:tb:

Hey,

A week that might not be enough…I’m a Project Manager not a developer !!!

:thumb: :thumb:

Hi,

Thanks for your help with this one…tonight I will print and read so be prepared for a question or three ! (No…I will try not to bother you)

In the mean time the final idea is to be able to draw a linking line between shapes so that the line snaps to the centre of the two chosen instance/objects.

If the shapes/ instances are then clicked and dragged around that the line stays connected between the objects.

If the mouse is hovered over the connecting line then it’s alpha is 50 and it can be deleted like any of the other objects you have coded with ‘d’

The connecting line can be drawn from any object to object ie it is possible to have more than one connecting line from an object.

If you think along the lines of Microsoft Visio where you got shapes and then you can connect them with connector lines so that you end up with linked shapes, but each object can be moved around and the lines will automatically follow.

The Dynamic text box will then follow the activities:

Square1 linked to Circle1, Cirlce2, Square1 linked to Circle3, Square2.

If the linking line where to be deleted from say the second link the text would read:

Square1 linked to Circle1, Cirlce2, Square1, Circle3, Square2.

If then Circle1 where to have a link drawn to Circle2:

Square1 linked to Circle1, Circle1 linked to Circle2, Square1, Circle3, Square2.

I guess the snap connector line and the dynamic text would be more difficult???

I suppose you need to start the process off from somewhere may be there is a linkage icon on the screen and when clicked listens for the first click on an instance/object (This then creates the centre snap line start point) then listens for the second click on another instance/object (This then completes the linkage and snaps to the centre of the second instance/object).

Could be a dotted line with arrow at the end of the linkage ie the second click.

The link will only be drawn if it comes in contact with an object hittest ???

The link cannot be drawn to istelf.

What do you think about attempting this one, would take time I am sure ?

All this is for my purposes only and is really appreciated…

See you soon…

… then as project manager arent you supposed to hire people to do this for you?

I am a Project Manager who in his own time wants to learn Flash MX and is doing so from the Flash MX Bible and with help from Clownstaples…this is purely something I want to do but without help will take a lot longer.

Have you ever had help starting something as a novice ???

[AS]
function addOne(){

   _root.selected=this.duplicateMovieClip(this._name+(++this.num),depth++);
   _root.selected.startDrag(true);
   _root.selected.onPress=grabit;
   _root.selected.onRollOver=selectit;
   _root.selected.onRollOut=deselectit;
   _root.selected.onRelease=dropit;
   _root.selected.drawline=_root.drawline;
   _root.names[_root.names.length]=" "+_root.selected._name;
   upDate();

}

function selectit(){
_root.selected=this;
this._alpha=50;
}
function deselectit(){
_root.selected=null;
this._alpha=100;
}
function grabit(){
if(_root.drawing)
{
_root.lines.pt[_root.lines.pt.length-1]=this;
_root.drawing=false;
}
else if (_root.beginLine){
this.drawline();
_root.beginline=false;
}
else
this.startDrag(false);

}
function dropit(){
this.stopDrag();
}
function onKeyDown(){
if(Key.getCode()==“D”.charCodeAt(0) &&
_root.selected!=null)
{
var p=_root.selected._name;
var s = " "+_root.names.toString();
var n = s.indexOf§;
_root.names=(s.substring(1,n)+
s.substring(n+p.length+2,s.length)).split(’,’);
if (n+p.length+2>=s.length)
_root.names.length–;
_root.selected.removeMovieClip();
_root.selected=null;
upDate();
}
else if (Key.getCode()==“L”.charCodeAt(0))
_root.beginLine=true;
//&&
// _root.selected!=null && !_root.drawing)
// _root.selected.drawline();

}
function dropnew(){
_root.selected.stopDrag();
}
function upDate(){
_root.currentnames=_root.names.toString();
_root.currentnames=_root.currentnames.substring(1,_root.currentnames.length);
}
function drawline(){
_root.lines.pt=_root.lines.pt.concat(this,_root.mous);
_root.lines.onEnterFrame=_root.updateline;
_root.drawing=true;
}
function updateline(){
this.clear();
this.lineStyle(1);
for (var i=0;i<this.pt.length-1;i+=2){
this.moveTo(this.pt*._x,this.pt*._y);
this.lineTo(this.pt[i+1]._x,this.pt[i+1]._y);
}
}
mous={};
function onEnterFrame(){
mous._x=_xmouse;
mous._y=_ymouse;
}

Key.addListener(this);
depth=0;
names=[];
things=[circle,triangle,square,trapezoid];
lines=createEmptyMovieClip(“lines”,99999);
lines._x=0;
lines._y=0;
lines.pt=[];
for(var i=0;i<things.length;i++) {
things*.onPress=addOne;
things*.onReleaseOutSide=dropnew;
}
stop();[/AS]
working on it

Morning,

I have looked at the linking file this morning and as you say there is no linking yet…I will look back regularly over the next day or so.

In addition I was searching through the posts to see what other stuff you have done and I must say you are bloody good.

Speak soon.

I completely missed it…on ‘L’ it does start the draw process…and as you mentioned it does not allow select and delete just yet or link the text below but anyho…brilliant work.