music_lp90 Posted August 27, 2008 Share Posted August 27, 2008 Hi, I'm trying to create a flash application that every time you click a button it places a new instance of a movie clip onto the stage that can be dragged and dropped.Here's the code I have so far:"draw_mc" is a movieclip the user clicks on to create as mony rectangles as they want.Right now when the user clicks on it, one rectangle will be created and can be dragged around, but if the user clicks it again, it disappears and a new one is created. var $i = 0;var $dynamicName = "a" + $i;draw_mc.onPress = function() : Void { $i++;}draw_mc.onPress = function() : Void { newRect($dynamicName, $i);}//User Functionsfunction newRect(instanceName, layer){ var rect = createEmptyMovieClip(instanceName, layer); rect.beginFill(0xcc00cc, 80); rect.moveTo(20, 20); rect.lineTo(140, 20); rect.lineTo(140, 140); rect.lineTo(20, 140); rect.endFill(); drag(rect); drop(rect);}function drag(a){ a.onPress = function(): Void { this.startDrag(); }}function drop(a){ a.onRelease = function(): Void { this.stopDrag(); }} Thanks for your help! Link to comment Share on other sites More sharing options...
justsomeguy Posted August 27, 2008 Share Posted August 27, 2008 Your $dynamicName variable only gets set once. You don't change it when $i changes. (also, in ActionScript you don't need to start variables with a dollar sign) Link to comment Share on other sites More sharing options...
music_lp90 Posted August 27, 2008 Author Share Posted August 27, 2008 EDIT: Nevermind I got it. Thanks!Thanks justsomeguy, can you help me with creating a dynamic name or is the name really not even the issue for creating multiple instances of the same movieclip?I tried this below to try and set the $dynamicName variable each time the user clicks, but it still doesn't work. var $i = 0;var $dynamicName = "a" + $i;draw_mc.onPress = function() : Void { $dynamicName = "a" + $i; $i++;}draw_mc.onPress = function() : Void { newRect($dynamicName, $i);}//User Functionsfunction newRect(instanceName, layer){ var $rect = createEmptyMovieClip(instanceName, layer); $rect.beginFill(0xcc00cc, 80); $rect.moveTo(20, 20); $rect.lineTo(140, 20); $rect.lineTo(140, 140); $rect.lineTo(20, 140); $rect.endFill(); drag($rect); drop($rect);}function drag(a){ a.onPress = function(): Void { this.startDrag(); }}function drop(a){ a.onRelease = function(): Void { this.stopDrag(); }} Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.