flash actionscript:
Hi Guys Any help here would be a blessing. I have created a a set of dynamic buttons using a loop, (not a for loop as i wanted each button to animate onto the stage using onMotionFinished. But I cannot remove them from the stage and seem to have some major targeting issues. I have tried to create an Array for the buttons created but things are going from bad to worse, if anyone can be botherd to try and understand my script and help me, i would be fully grateful Many thanks Jim import mx.transitions.Tween; import mx.transitions.easing.*; var my_xml = new XML(); my_xml.ignoreWhite = true; my_xml.onLoad = function(success) { if (success) { trace(success); //getData(); //trace(my_xml); } else { trace("xml error"); } }; my_xml.load("xml/portfolio.xml"); var work:Array = new Array(); var buttonList:Array = new Array(); var i = 0; var rowshifter = 0; var clipCounter = 0; var scope = this.main_mc; var buttonAmount = 0; function getWorkData() { var portfolioArray:Array = my_xml.firstChild.childNodes; var workArray:Array = my_xml.firstChild.firstChild.childNodes; var sketchArray:Array = my_xml.firstChild.firstChild.nextSibling.childNodes; var animationArray:Array = my_xml.firstChild.lastChild.childNodes; for (var i = 0; i<workArray.length; i++) { var workClient = workArray[i].firstChild.childNodes; var workTitle = workArray[i].firstChild.nextSibling.childNodes; var workThumb = workArray[i].firstChild.nextSibling.nextSibling.childNodes; var workDesc = workArray[i].firstChild.nextSibling.nextSibling.nextSibling.childNodes; var workImages = workArray[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.childNod es; var workLink = workArray[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibl ing.childNodes; work.push({Client:workClient, Title:workTitle, Thumb:workThumb, Description:workDesc, Images:workImages, Link:workLink}); //delete work; } makeButtons(); //trace(work[1]["Title"]); //trace("portfolioList " + portfolioArray[0]); //trace("workList " + workArray.length + workArray[0]); //trace("sketchList " + sketchArray.length + sketchArray[0]); //trace("animationList " + animationArray.length + animationArray[0]); } function makeButtons() { if (i<work.length) { buttonList.push("button_mc"+i); if (clipCounter>11) { rowshifter++; clipCounter = 0; } var myButton = scope.menu_mc.attachMovie("button_mc", "button_mc"+i, i, {buttonClient:work[i]["Client"], buttonTitle:work[i]["Title"]}); myButton._x = (myButton._width+5)*clipCounter; myButton._y = (myButton._height+7)*rowshifter; clipCounter++; //trace(work.length); var mytween = new Tween(myButton.shapemove, "_yscale", Bounce.easeOut, 0, 100, 1, false); mytween.onMotionFinished = function() { buttonAmount++; makeButtons(); trace(myButton); //trace(buttonAmount); //trace(buttonList[0]); }; i++; myButton.onRollOver = function() { trace(myButton); //trace(buttonList[i]); //scope.image_holder.loadMovie(this.buttonThumb); scope.des_txt.text = this['buttonDes']; scope.info_txt.text = this['buttonTitle']; //scope.client_txt.text = this['buttonClient']; //scope.slink_txt.text=this['buttonLink'], URL=this['buttonLink']; } } else { trace(buttonList); //delete work; //trace("new work "+work); //trace(buttonList.length); } }; function removeButtons() { trace(buttonAmount); if (buttonAmount > 0) { var mytween = new Tween(scope.menu_mc.button_mc[buttonAmount].shapemove, "_yscale", Bounce.easeIn, 100, 0, 1, false); mytween.onMotionFinished = function() { removeMovieClip(myButton[buttonAmount]); buttonList.pop(); trace("newlength"+buttonList.length); buttonAmount--;; removeButtons(); }; } else { delete work; trace("delete work Array (print as undefined) " + work); } } // BUTTON ACTIONS scope.workButton.onRelease = function() { newData = "workData"; trace("fired"); removeButtons(); }; scope.loadButton.onRelease = function() { rowshift = 0; clipCounter = 0; getWorkData(); trace("getting Data....."); }; stop();
your button names are scope.menu_mc"button_mc"+i]. or if you want to store those names in your buttonList array do so after they are created. you can use the following: var myButton = scope.menu_mc.attachMovie("button_mc", "button_mc"+i, i, {buttonClient:work[i]["Client"], buttonTitle:work[i]["Title"]}); buttonList.push(myButton); and to remove those buttons use: removeMovieClip(buttonList[buttonAmount]);
Thanks kglad That worked a treat, just couldnt figure out how i should be targeting the array. I have another issue with this. I have set the arrays to delete once the remove has interated through the buttons, but on the second load of the buttons the buttonList Array is added to as though the array has not been cleared. Below is my code: function removeButtons() { buttonTotal = buttonList.length; if (buttonTotal > -1){ var mytween = new Tween(scope.menu_mc["button_mc"+ buttonTotal].shapemove, "_yscale", Bounce.easeIn, 100, 0, 1, false); mytween.onMotionFinished = function() { buttonList.pop(); scope.menu_mc["button_mc"+ buttonTotal].removeMovieClip(); removeButtons(); } } else { delete work; delete buttonList; trace("delete work Array (print as undefined) " + work); trace("delete buttonList Array (print as undefined) " + buttonList); } }
if shapemove is a child movieclip of your movieclips in buttonList() use: function removeButtons() { var mytween = []; for (var i = 0; i<buttonList.length; i++) { mytween[i] = new Tween(buttonList[i].shapemove, "_yscale", Bounce.easeIn, 100, 0, 1, false); mytween[i].onMotionFinished = function() { scope.menu_mc["button_mc"+i].removeMovieClip(); }; } delete buttonList; trace("delete work Array (print as undefined) "+work); trace("delete buttonList Array (print as undefined) "+buttonList); }
Thanks for all your help kglad.
Don't see what you're looking for? Try a search.
|