Hello,
I have created an application that dynamically create MCs, drag them, deletes them, and then repeats as necessary.
I am having trouble targeting the variable number after the dynamic MC name.
I create a variable called containerType then append a counter on it. I try to target the dynamic MC as follows:
_root[“containerType”+mcType]
but it doesn’t work.
Is it because the var is only contained within the function. Is there are way to get the name to stick?
Should I create a prototype “ID” to associate with the MC instance name?
Should I create a class file and have a property “name”?
Right now, I have hard coded the target MC name, but that doesn’t work in a dynamic application that could have a lot more instances that the numbers hard coded.
I want to create these MCs and talk to them dynamically.
mcType=0;
//create a new instance of type 1 MC when clicked
type1Btn.onRelease=function(){
makeIt(type1Btn);
}
//create a new instance of type 2
type2Btn.onRelease=function(){
makeIt(type2Btn);
}
// Make a new dynamic MC
function makeIt(selectType) {
mcType++;
containerType = selectType.duplicateMovieClip("containerType"+mcType, mcType, 1);
//Randomly position them
//How can I use Math.round with this???
_root.containerType._x = 300 + Math.random()*20-10;;
_root.containerType._y = 200 + Math.random()*20-10;
currentSelection=containerType;
currentSelection.onMouseDown=dragIt;
currentSelection.onMouseUp=stopIt;
}
//
//drag the current selection
dragIt = function() {
startDrag(currentSelection);
};
//stop
stopIt = function() {
stopDrag();
};
// MC Controller to check events
type1Btn.onEnterFrame=function(){
//Mouse Selection
//This part is the hard coded part that I want to make dynamic
//I have tried _root["containerType"+mcType] but it does not work
//If the mouse hits the MC then it becomes the current one to drag
if(_root.containerType1.hitTest(_root._xmouse, _root._ymouse, false)){
currentSelection=_root.containerType1
}
//Trash
if(_root.containerType1.hitTest(_root.trashMc)){
removeMovieClip(_root.containerType1);
}
}
//
stop();