RE: [Flashcoders] recursive question?
Real quick idea,not tested (the code below could probably be made better with a rest statement - see link below), how about not doing it recursively (because that's why it's calling remove more than once), but doing something like this: import flash.display.Sprite; private function removePrevious():void { if (xAxis!=null) { removeChild(xAxis); xAxis = null; } if (yAxis!=null) { removeChild(yAxis); yAxis = null; } } private function renderAxis(which:String):void removePrevious(); switch (which) { case (X) : xAxis = new Sprite(); draw([xAxis]); break; case (Y) : var yAxis:Sprite = new Sprite(); draw([yAxis]); break; case (both) : var xAxis:Sprite = new Sprite(); var yAxis:Sprite = new Sprite(); draw([xAxis, yAxis]); break; } } private function draw(axes:Array):void { for (var i:int = 0; i numAxes; i++) { addChild(axes[i]); } } Or for the draw method, use a rest parameter instead of an array: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f56.html Jason Merrill Bank of America Instructional Technology Media · GCIB Staff Support LLD Interested in Flash Platform technologies? Join the Bank of America Flash Platform Developer Community Interested in innovative ideas in Learning? Check out the Innovative Learning Blog and subscribe. -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Mendelsohn, Michael Sent: Wednesday, January 14, 2009 2:28 PM To: Flash Coders List Subject: [Flashcoders] recursive question? Hi list... I have two functions, where either an X is rendered, a Y is rendered, or both an X and a Y. removePrevious() is called before anything gets rendered, so as to clear the stage. The problem is when both are rendered, removePrevious() is called twice. It first clears the stage, renders a new x, then renders a new y -- but not before removing that newly just created X. How can I avoid this? Thanks, - Michael M. private function removePrevious():void { if (xAxis!=null) { removeChild(xAxis); xAxis = null; } if (yAxis!=null) { removeChild(yAxis); yAxis = null; } } private function renderAxis(which:String):void removePrevious(); switch (which) { case (X) : xAxis = new Sprite(); addChild(xAxis); break; case (Y) : yAxis = new Sprite(); addChild(yAxis); break; case (both) : renderAxis(X); renderAxis(Y); break; } } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] recursive question?
I would probably just do something like... private function renderAxis(which:String, doRemove:Boolean = true):void if(doRemove){removePrevious();} switch (which) { case (X) : xAxis = new Sprite(); addChild(xAxis); break; case (Y) : yAxis = new Sprite(); addChild(yAxis); break; case (both) : renderAxis(X,false); renderAxis(Y,false); break; } } On Wed, Jan 14, 2009 at 11:27 AM, Mendelsohn, Michael michael.mendels...@fmglobal.com wrote: Hi list... I have two functions, where either an X is rendered, a Y is rendered, or both an X and a Y. removePrevious() is called before anything gets rendered, so as to clear the stage. The problem is when both are rendered, removePrevious() is called twice. It first clears the stage, renders a new x, then renders a new y -- but not before removing that newly just created X. How can I avoid this? Thanks, - Michael M. private function removePrevious():void { if (xAxis!=null) { removeChild(xAxis); xAxis = null; } if (yAxis!=null) { removeChild(yAxis); yAxis = null; } } private function renderAxis(which:String):void removePrevious(); switch (which) { case (X) : xAxis = new Sprite(); addChild(xAxis); break; case (Y) : yAxis = new Sprite(); addChild(yAxis); break; case (both) : renderAxis(X); renderAxis(Y); break; } } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] recursive question?
Right Taka, thinking the same thing, and I was just assuming he was doing something more (not shown) in the draw function other than just adding the child - otherwise, you're just adding blank things to the screen. Jason Merrill Bank of America Instructional Technology Media · GCIB Staff Support LLD Interested in Flash Platform technologies? Join the Bank of America Flash Platform Developer Community Interested in innovative ideas in Learning? Check out the Innovative Learning Blog and subscribe. -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Taka Kojima Sent: Wednesday, January 14, 2009 3:09 PM To: Flash Coders List Subject: Re: [Flashcoders] recursive question? I would probably just do something like... private function renderAxis(which:String, doRemove:Boolean = true):void if(doRemove){removePrevious();} switch (which) { case (X) : xAxis = new Sprite(); addChild(xAxis); break; case (Y) : yAxis = new Sprite(); addChild(yAxis); break; case (both) : renderAxis(X,false); renderAxis(Y,false); break; } } On Wed, Jan 14, 2009 at 11:27 AM, Mendelsohn, Michael michael.mendels...@fmglobal.com wrote: Hi list... I have two functions, where either an X is rendered, a Y is rendered, or both an X and a Y. removePrevious() is called before anything gets rendered, so as to clear the stage. The problem is when both are rendered, removePrevious() is called twice. It first clears the stage, renders a new x, then renders a new y -- but not before removing that newly just created X. How can I avoid this? Thanks, - Michael M. private function removePrevious():void { if (xAxis!=null) { removeChild(xAxis); xAxis = null; } if (yAxis!=null) { removeChild(yAxis); yAxis = null; } } private function renderAxis(which:String):void removePrevious(); switch (which) { case (X) : xAxis = new Sprite(); addChild(xAxis); break; case (Y) : yAxis = new Sprite(); addChild(yAxis); break; case (both) : renderAxis(X); renderAxis(Y); break; } } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] recursive question?
Interesting answers, Jason and Taka. Thanks very much! In migrating to AS3, I guess I have to be reminded about simply removing the child. - MM ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] recursive question?
Oh trust me Jason, there's *plenty* more going on besides blank things. :-D - MM Right Taka, thinking the same thing, and I was just assuming he was doing something more (not shown) in the draw function other than just adding the child - otherwise, you're just adding blank things to the screen. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] recursive question?
Well, I generally ask myself two questions when I find myself writing a recursive functioin: does using a recursive function actually simplify things here? Do I actually need to use it? I.e. don't use recursive functions for the sake of having a recursive function -- you will find that you actually don't have to use them very often, and if you find yourself using one you should question whether or not it is really needed... a lot of times (as in this case) the answer will be no. But then again, you may have simplified your app for the sake of an example and you might be doing more things where it would make sense for a recursive function - Taka On Wed, Jan 14, 2009 at 12:29 PM, Merrill, Jason jason.merr...@bankofamerica.com wrote: Right Taka, thinking the same thing, and I was just assuming he was doing something more (not shown) in the draw function other than just adding the child - otherwise, you're just adding blank things to the screen. Jason Merrill Bank of America Instructional Technology Media · GCIB Staff Support LLD Interested in Flash Platform technologies? Join the Bank of America Flash Platform Developer Community Interested in innovative ideas in Learning? Check out the Innovative Learning Blog and subscribe. -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto: flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Taka Kojima Sent: Wednesday, January 14, 2009 3:09 PM To: Flash Coders List Subject: Re: [Flashcoders] recursive question? I would probably just do something like... private function renderAxis(which:String, doRemove:Boolean = true):void if(doRemove){removePrevious();} switch (which) { case (X) : xAxis = new Sprite(); addChild(xAxis); break; case (Y) : yAxis = new Sprite(); addChild(yAxis); break; case (both) : renderAxis(X,false); renderAxis(Y,false); break; } } On Wed, Jan 14, 2009 at 11:27 AM, Mendelsohn, Michael michael.mendels...@fmglobal.com wrote: Hi list... I have two functions, where either an X is rendered, a Y is rendered, or both an X and a Y. removePrevious() is called before anything gets rendered, so as to clear the stage. The problem is when both are rendered, removePrevious() is called twice. It first clears the stage, renders a new x, then renders a new y -- but not before removing that newly just created X. How can I avoid this? Thanks, - Michael M. private function removePrevious():void { if (xAxis!=null) { removeChild(xAxis); xAxis = null; } if (yAxis!=null) { removeChild(yAxis); yAxis = null; } } private function renderAxis(which:String):void removePrevious(); switch (which) { case (X) : xAxis = new Sprite(); addChild(xAxis); break; case (Y) : yAxis = new Sprite(); addChild(yAxis); break; case (both) : renderAxis(X); renderAxis(Y); break; } } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders