views:

150

answers:

1

hi,

1) if I create items in a for loop, is correct to add a new eventListener for each item ? Or should I add only 1 eventListener to the parent ? and call the event through ID ?

2) if I want to scale my item, (a LinkButton with icon image), I noticed that the icon is sometimes resized with delay, so I have a bit of flickering when I trigger the event. Should I not use icons, and set the image in another way ? How can I fix this ?

thanks

A: 

1) if I create items in a for loop, is correct to add a new eventListener for each item ? Or should I add only 1 eventListener to the parent ? and call the event through ID ?

It depends. If the items are listening for something, add it to them. If the parent is listening, add it to the parent. If you add it only to the parent, set the useCapture arg to true in the addEventListener method. It can get confusing in Flash because there is no difference between an event listener and an event handler: the handler actually points to the class that contains the handler.

2) if I want to scale my item, (a LinkButton with icon image), I noticed that the icon is sometimes resized with delay, so I have a bit of flickering when I trigger the event. Should I not use icons, and set the image in another way ? How can I fix this ?

Without knowing how exactly you are doing this, I can't offer concrete solutions. Are you using a Resize effect? Are you scaling using overrides on scaleX and scaleY properties? Does this handle on mouseover or via some other event? All I can tell you is that you may be better off not using the LinkButton, or may want to change the skin instead of resizing. Show your code if you want more informed answers.

Robusto
thanks for reply. So (1), I have 35 items.. should I add 35 eventListeners ? I thought I can use 1 eventListener and set something like e.target.name == "childName".(2) I'm using scaleX scaleY properties, on mouseOver event. I'm using now a custom component and it seems better.
Patrick
@Patrick: You can set one event listener in the parent (or wherever up the chain) and listen for the event. The issue is, you will have to be able to identify the components that are dispatching those events, because the mouseover will fire for every mouseOver event and your handler will be called. A smarter way to do this is to have the components dispatch a custom event on mouseOver, which may potentially pare down the realm of handler calls significantly.
Robusto
mhm, so you are saying, each children dispatch a customEvent having the children reference as attribute, so I don't need to identify it ? something like this ?
Patrick
It doesn't need the child reference as an attribute, because event.currentTarget should handle that. The important thing is that in your container or component parent (whatever contains the listener that handles the event) you check for the event dispatcher and either call its resize method or do whatever other mojo you were going to do with that information.
Robusto