<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Well but, you should also know that closures are sort of a bad deal because they retain references that can get stuck in memory. So in that way, I think your system of having an arguments parameter was cleaner because it avoids an extra closure that retains references to the addCallback() arguments.<div><br></div><div>There are some articles about closures out there online somewhere if you search but be sure they are about AS3 / AVM2 which is a totally different thing than AS2 / AVM1.</div><div><br></div><div>You can also see the number of method closures in memory listed in the Flex debugger's memory profiler. You could build your system then do a test in Flex that makes thousands of tween instances and callbacks, then deletes the tweens, to see if the closures "stick" or not... I haven't played with that level of stuff much. However, this is also kind of tricky because the GC does not sweep until it needs to, meaning that even if closures do stick at first, your test would need to cycle itself infinitely so you can see how it operates over time.</div><div><br></div><div>Or, ignore the low level issues and just have fun, do what works ... in the end it won't affect things very much either way so maybe it's a waste of time to worry about. :-)</div><div><br></div><div>- m<br><div><div><br></div><div><br><div><div>On May 21, 2008, at 1:03 PM, Jud Holliday wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div lang="EN-US" link="blue" vlink="purple" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div class="Section1"><div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(0, 112, 192); ">More comments below</span><span style="color: rgb(0, 112, 192); "><br><br><o:p></o:p></span></div><div><div><div style="margin-left: 0.5in; "><div style="text-indent: -0.25in; margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">1.</span><span style="font-size: 7pt; color: rgb(31, 73, 125); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="apple-converted-space">&nbsp;</span></span><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Am I going about this in an overly complicated way?/Is there already a system in place to accomplish this?</span><span style="color: black; "><o:p></o:p></span></div></div></div></div><div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p>&nbsp;</o:p></div></div><div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">Like Donovan said you can already pass arguments using a nested closure. However, that tends to be kind of illegible so i think that your system makes a lot of sense.<o:p></o:p></div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "><o:p>&nbsp;</o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(0, 112, 192); ">Thanks Donovan/Moses! &nbsp;I didn’t know about nested closure. I definitely prefer to keep the syntax clear, but I can use nested closure behind the scenes and greatly simplify the class. No more need to override the ‘dispatch’ method. Now the method in question looks like this:<o:p></o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(0, 112, 192); "><o:p>&nbsp;</o:p></span></div></div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(0, 112, 192); ">public function addCallbackWithParams(closure : Function, type:String=GoEvent.START, args:Array = null):void<o:p></o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(0, 112, 192); ">{<o:p></o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(0, 112, 192); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //uses nested closure to pass arguments to the function<o:p></o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(0, 112, 192); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super.addCallback( function():void{ closure.apply(null, args); }, type);<o:p></o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(0, 112, 192); ">}<o:p></o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(31, 73, 125); "><o:p>&nbsp;</o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><br><br><o:p></o:p></div><div><div><div style="margin-left: 0.5in; "><div style="text-indent: -0.25in; margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">2.</span><span style="font-size: 7pt; color: rgb(31, 73, 125); ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="apple-converted-space">&nbsp;</span></span><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">If not, then does addCallbackWithParams make sense, or is there another way to add the ability to pass parameters to a callback in LinearGo? This seems like a really handy feature.</span><span style="color: black; "><o:p></o:p></span></div></div></div></div><div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p>&nbsp;</o:p></div></div></div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">I like it a lot. The other approach which i almost took with Go (until someone pointed out the nested closure thing, at which time i figured that was far simpler), was to have a special callback class, that wrapped the closure, the arguments, and the GoEvent type to associate the callback to. One nice thing about having such a class is that you can pass callbacks in an array, and each one defines its own type. However, your approach is nice and simple too.<o:p></o:p></div><div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p>&nbsp;</o:p></div></div><div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">I think it's a great topic to be discussing. The ultimate thing would be something that worked anywhere around the Go kit (with physics animations eventually). You know Jud, I think the best version of the class you're writing there would be to just implement IPlayable/PlayableBase but not extend LinearGo. That way you have a 'playable callback' class that can be included in groups as you're doing here, but can be used directly without LinearGo's overhead or extra features.<span style="color: rgb(31, 73, 125); "><o:p></o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(0, 112, 192); "><o:p>&nbsp;</o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(0, 112, 192); ">Ah, I think I see what you mean. I will take a look at changing that and let you know if I have questions.<o:p></o:p></span></div></div><div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(0, 112, 192); "><o:p>&nbsp;</o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(0, 112, 192); ">-Jud<o:p></o:p></span></div></div><div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p>&nbsp;</o:p></div></div><div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p>&nbsp;</o:p></div></div><div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p>&nbsp;</o:p></div></div><div><div style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p>&nbsp;</o:p></div></div></div>_______________________________________________<br>GoList mailing list<br><a href="mailto:GoList@goasap.org" style="color: blue; text-decoration: underline; ">GoList@goasap.org</a><br><a href="http://goasap.org/mailman/listinfo/golist_goasap.org" style="color: blue; text-decoration: underline; ">http://goasap.org/mailman/listinfo/golist_goasap.org</a><br></div></span></blockquote></div><br></div></div></div></body></html>