Skip to main content
December 4, 2009
Answered

Drag & Drop Confusion

  • December 4, 2009
  • 1 reply
  • 571 views

Good evening AS3 programmers,

I apologize, but this is another newbie question. I programmatically added 20 instances of a movie clip named "Token" to the stage.  Token consists of a small rectangle and a dynamic text field.  Each instance of Token was named "tkn."  I'm attempting implement drag & drop for these movie clips.  In the drag function which is called by the Mouse_Down event I've traced e.target.name.  Instead of getting the name of the movie clip, tkn, I get name of the text field contained within tkn.  After a lot of searching I found the mouseChildren property and within the code for the movie clip I now have the statement "this.mouseChildren = false;"  This change corrected the name problem.  I no longer get the name of the text field, but the movie clip name has been changed to "instancexxx," where xxx is a 3 digit number.  Since I only want to drag the tkn movie clips I am testing e.target.name. How do I get Flash to keep the name of the movie clip as tkn?  Thanks for your help on this.

This topic has been closed for replies.
Correct answer Rothrock

How are you "naming" the clips. My guess is you are doing something like this:

for(var i=0;i<5;i++){

var tkn:MovieClip=new MovieClip();

}

In that case you aren't naming the clip "tkn" you are reusing a variable called "tkn" to reference a movieclip. In AS2 that would be the name, but in AS3 the name is a separate property. You are getting instance## because all clips have a name property, but if a specific one isn't assigned, flash just keeps track and gives them their number. You would need to add a line like

tkn.name="tkn"

after the construction of your clips. However I think you are likely to run into problem is all the clips have the same name. Especially if you try and reference the clip by its name. Instead you might want to "add" a "type" or something property to each clip as it is created. That way you can check the type and see what it is.

1 reply

RothrockCorrect answer
Inspiring
December 4, 2009

How are you "naming" the clips. My guess is you are doing something like this:

for(var i=0;i<5;i++){

var tkn:MovieClip=new MovieClip();

}

In that case you aren't naming the clip "tkn" you are reusing a variable called "tkn" to reference a movieclip. In AS2 that would be the name, but in AS3 the name is a separate property. You are getting instance## because all clips have a name property, but if a specific one isn't assigned, flash just keeps track and gives them their number. You would need to add a line like

tkn.name="tkn"

after the construction of your clips. However I think you are likely to run into problem is all the clips have the same name. Especially if you try and reference the clip by its name. Instead you might want to "add" a "type" or something property to each clip as it is created. That way you can check the type and see what it is.

December 4, 2009

Rothrock,

Bingo!  One guess and you nailed my problem.  I have given the text field of each instance a unique string which will, I hope, allow me to know who is who.  Many thanks.