Question
Create Drag and Drop Movie Clips Dynamically
I'm creating a game with an inventory system which updates
and adds a movie clip as the user clicks on an item to add to it.
If the user clicks on itemBtn, the user adds a new item (placeMC+itemNum) in the inventory system. Now the user must be able to drag the new item into its target destination. Does anyone know how to use drag and drop in a dynamically created movie clip? Or would you suggest any other alternative?
Here's my code, it won't work:
itemCtr = 0;
itemBtn.onRelease = function(){
newName = "placeMC"+itemCtr;
newPos = placeMC._x + 120 * itemCtr;
duplicateMovieClip(placeMC, newName ,itemCtr+1); //this.getNextHighestDepth()
loadMovie("gamit/icon"+itemCtr+".jpg", [newName]);
setProperty(newName, _x, newPos);
set("placeMC"+itemCtr, newPos);
itemCtr++;
//track the item in position
}
this["placeMC"+itemCtr].onPress = function(){
startDrag(this,true);
}
this["placeMC"+itemCtr].onRelease = function(){
stop();
if(this["placeMC"+itemCtr].hitTest(destinationMC) == true){
setProperty(this,_visible, false);
}
}
Any suggestions would be highly appreciated. Thank you!
If the user clicks on itemBtn, the user adds a new item (placeMC+itemNum) in the inventory system. Now the user must be able to drag the new item into its target destination. Does anyone know how to use drag and drop in a dynamically created movie clip? Or would you suggest any other alternative?
Here's my code, it won't work:
itemCtr = 0;
itemBtn.onRelease = function(){
newName = "placeMC"+itemCtr;
newPos = placeMC._x + 120 * itemCtr;
duplicateMovieClip(placeMC, newName ,itemCtr+1); //this.getNextHighestDepth()
loadMovie("gamit/icon"+itemCtr+".jpg", [newName]);
setProperty(newName, _x, newPos);
set("placeMC"+itemCtr, newPos);
itemCtr++;
//track the item in position
}
this["placeMC"+itemCtr].onPress = function(){
startDrag(this,true);
}
this["placeMC"+itemCtr].onRelease = function(){
stop();
if(this["placeMC"+itemCtr].hitTest(destinationMC) == true){
setProperty(this,_visible, false);
}
}
Any suggestions would be highly appreciated. Thank you!