Thanks, Kerry and allandt. I will take your recommendations, allandt. Kerry, when you said that I would end up with only the last DynaBtn, that is true. But I wanted to ask about the solution I found using that DynaBtn handler with the parameter. It returns the function and so it works. My question is, is the better solution to create a separate class? More interesting for me is, can it work without creating a separate class? Any elucidation would be appreciated. Thanks again!
On Wed, Jul 7, 2010 at 6:55 AM, allandt bik-elliott (thefieldcomic.com) < [email protected]> wrote: > does this line work? > > > DynaBtn.addEventListener(MouseEvent.MOUSE_OVER,DynaBtnRollOverHandler(CityNum)); > > i wouldn't have thought it would (by using the brackets you are calling > that > function straight away) > > it should be > > DynaBtn.addEventListener(MouseEvent.MOUSE_OVER,DynaBtnRollOverHandler); > } > > private function DynaBtnRollOverHandler(e:Event):void > { > // handle event > } > > and cityNum should be a property on DynaBtn so that you can use > (e.target as DynaBtn).cityNum > to recall the correct number > > best > a > > On 7 July 2010 14:40, Kerry Thompson <[email protected]> wrote: > > > J.C. Berry wrote: > > > > > I wondered if I could bother you to review the code below and make > > comments > > > and suggestions. > > > > It's not bad at all, especially for your first class. I didn't go > > through all your code, but one thing jumped out at me. These lines > > might give you problems: > > > > for(var i=0;i<NumOfCities;i++){ > > CityNum = i; > > var DynaBtn = root['city'+CityNum+'_mc']; > > DynaBtn.gotoAndStop(1); > > > > > > DynaBtn.addEventListener(MouseEvent.MOUSE_OVER,DynaBtnRollOverHandler(CityNum)); > > DynaBtn.addEventListener(MouseEvent.MOUSE_OUT,DynaBtnRollOutHandler); > > > > First, you are going to have only one DynaBtn variable--the last one > > declared in the for loop. Each time you create an instance, it > > overwrites the last one. Fortunately for you, it works, but it won't > > always. > > > > The second issue is adding an event listener from outside the object. > > DynaBtn.addEventListener() will add the listener to the button, but > > you won't be able to remove the listener from outside the button. > > > > Instead, you should have a DynaBtn class, and add the listener in the > > constructor. Then you can remove the event listeners when you clean > > up. > > > > This applies, of course, to all the buttons you created. > > > > Nice job overall, though. > > > > Cordially, > > > > Kerry Thompson > > _______________________________________________ > > Flashcoders mailing list > > [email protected] > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > _______________________________________________ > Flashcoders mailing list > [email protected] > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

