Groups | Blog | Home
all groups > flash actionscript > august 2007 >

flash actionscript : Get _txt name


sbryner
8/23/2007 8:11:45 PM
Hey all,

How do I get the name of a _txt or _mc that I drag an MC over?

I can drag a_mc to b_txt and when it does I want to store b_txt's name into a
variable getMcName()
That way if i drag a_mc over c_txt it would store that name instead.


I think I have to use .hitTest but not sure how it actually can get the name?
any ideas?


Seems so simple.


sky
SymTsb
8/23/2007 8:34:58 PM
sbryner
8/23/2007 8:45:25 PM
I'm trying to store the name I drag my movieClip over into a variable.

Say I'm dragging around the screen "A_mc" and I drag it over "B_txt"
I want the variable "getMcName" to store "B_txt.name"

I just don't know how to collect the name when "A_mc" intersects or collides
with
"B_txt" Do you know how to do that?

thanks,

sky

8/23/2007 9:32:57 PM
[quoted text, click to view]

Sky,

Here is a sample I made to show you how to make this work:

var myVar:String;

box_mc.onPress = function() {
this.startDrag();
this.onEnterFrame = findTxt;
};

box_mc.onRelease = function() {
this.stopDrag();
delete this.onEnterFrame;
};

var txtArray:Array = new Array("testingTxt_mc", "testing2Txt_mc");

function findTxt() {
for (var i:Number = 0; i < txtArray.length; i++) {
if (box_mc.hitTest(textBoxes_mc[txtArray[i]])) {
myVar = textBoxes_mc[txtArray[i]].test_txt.text;
trace(myVar);
}
}
}

First, the hitTest only works with movieclips and not text fields. So
you want to make sure you put your dynamic text fields (give the txt
fields the same instance name, I used test_txt) into their own
movieclips (in the example I put the dynamic txt field containing the
word "testing" inside of a movieclip with the instance name
testingTxt_mc and a dynamic txt field containg the word "working" in a
MC with the instance name testing2Txt_mc. you want to store these
movieclip names in an array. A for loop is used to run through that
array of movieclips to test each one to see if that is what box_mc is
hitting (box_mc is the name of the clip I am dragging around to hit
these MC's). to keep it contained...I placed both of my MC's with the
txt fields inside of them into another MC with the instance name
textBoxes_mc. myVar is a variable that will hold the string eachtime
a new text box is dragged onto. Try this out and let me know if you
can follow it. Good luck!
NSurveyor
8/24/2007 4:43:53 AM
When a MovieClip is dragged using startDrag, the Object you drag the MovieClip
over is stored in MovieClip._droptarget, but in Slash notation for some reason.
Example code for A_mc:

A_mc.onPress = function(){
this.startDrag();
this.onMouseMove = function(){
getMcName = eval(this._droptarget)._name;
}
}
mc.onMouseUp = function(){
this.stopDrag();
delete this.onMouseMove;
}
sbryner
8/27/2007 9:29:26 PM
exactly what I was hoping for.
Thank you it works great.
I was stuck on

this.onMouseMove = function(){
getMcName = eval(this._droptarget)._name;
}

thanks for the help
AddThis Social Bookmark Button