That looks good to me if the logic for the add, remove, first, etc. is simple. It's a catch 22.
- If it's simple, then you can add 1 to 3 lines of code in your case statement, that way, the function is big, but still readable. Since it's once function, it's less RAM, and not overally processor intensive, just not as efficient as an if then (but more readable). - If it's REALLY simple, meaning each case statement merely calls a function, you might as well add a Delegate to each event listener when you register for click because then you negate the need for a switch; meaning, there is already functions setup to do those operations, so you ought to just forward the calls to their appropriate functions. You'll have a slightly more processor intensive initialization of your class, but I doubt you or anyone will notice. You'll also have more functions floating around in RAM, but it doesn't sound like your class is that huge or used more than once since it's a ViewStack. When I'm in a hurry, or my class is simple, I just use the switch statement, merely because there isn't much logic that goes into the button presses and it's ok to fit it into my click function, nested in the cases because it won't add too much bloat to the function. However, if things start to get complex, I'll use Delegate with new functions to make the code more clean and easily readable/manageable. So, it's more of a question of approrpriateness(sp?) vs. best-practice. For now, if you dig your click function below, I'd stick with that. ----- Original Message ----- From: <[EMAIL PROTECTED]> To: <[email protected]> Sent: Monday, February 07, 2005 9:25 AM Subject: Re: [flexcoders] codeless MXML seprate AS class help Hi JesterXL, my component consists of a viewstack with 1-"X" children. each child contains a textfeild. 1 button adds a child, 1 removes a child, 1 maked the tf in a child editable, the other 4 navigate through the viewstack. so I can add this to my class? public function click(event_obj:Object):Void { switch(event_obj.target) { case add_pb: // create child in viewstack break; case remove_pb: // do child in viewstack break; case edit_pb: // do edit current tf in viewstack break; case first_pb: // goto first child in view stack break; case previous_pb: // goto previous child in viewstack break; case next_pb: // goto next child in viewstack break; case last_pb: // goto last child in viewstack break; } } I'm trying to build my component based on the temperature converter sample. is this the best practice on doing this? thanks, -Art Quoting JesterXL <[EMAIL PROTECTED]>: > You can either do a variation on what Abdul said using target, or use > Delegate to forward to different functions: > > > Smart click: > > cancel_pb.addEventListener("click", this); > submit_pb.addEventListener("click", this); > > function click(event_obj:Object):Void > { > switch(event_obj.target) > { > case cancel_pb: > // do cancel stuff; > break; > > case submit_pb: > // do submit stuff > break; > } > } > > Or, Delegate to forward: > > import mx.utils.Delegate; > cancel_pb.addEventListener("click", Delegate.create(this, onCancel)); > submit_pb.addEventListener("click", Delegate.create(this, onSubmit)); > > function onCancel(event_obj:Object):Void > { > // do cancel stuff > } > > function onSubmit(event_obj:Object):Void > { > // do submit stuff > } > > > ----- Original Message ----- > From: "Abdul Qabiz" <[EMAIL PROTECTED]> > To: <[email protected]> > Sent: Monday, February 07, 2005 8:42 AM > Subject: RE: [flexcoders] codeless MXML seprate AS class help > > > > Hi Art, > > I couldn't get what you are asking. Do you mean to have separate event > handler for all seven buttons in MXML? > > What I interpret, you have seven buttons in mxml and one click function > handling the click events for those buttons. You can identify the button > clicked by using "event.target.id". > > > function click(event) > { > var target = event.target.id; > > switch(id) { > > case "button1": > //do something > break; > case "button2": > //do something > break; > case "button3": > //do something > break; > } > } > > > > > Does it help? Please give us more details? > > -abdul > > > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Monday, February 07, 2005 6:36 PM > To: [email protected] > Subject: [flexcoders] codeless MXML seprate AS class help > > > Hi All, > > I'm trying to make my class seprate from my MXML. I'm following the simple > example founf in the docs but I've ran into one problem. How do I define > multiple click events from different buttons? I have 7 at the moment and > for > the life of me I can't find an example w/ more than one button click > function. > > thanks, > -Art > > > > > Yahoo! Groups Links > > > > > > > > > > Yahoo! Groups Links > > > > > > > > > > Yahoo! Groups Links > > > Yahoo! Groups Links

