View Full Version : Eventlistener to sprite in loop?
Ancide
October 26th, 2007, 06:27 AM
Ok, I have a loop which loops out 10 empty movie clips and then adds 10 sprites inside those movieclips.
What I want to do is to change the alpha of the sprite I hover. But since I can't add eventlistener to the sprite how can change it's alpha?
Can't just use:
private function hoverSprite(event:MouseEvent)
{
spritename.alpha = 0.5;
}
Because then only the last looped sprite will change alpha then.
Dazzer
October 26th, 2007, 07:07 AM
Why can't you add eventlistener to sprite? You can add the same listener to different sprites even.
Then use event.target to get the sprite which dispatched the event.
Ancide
October 26th, 2007, 07:33 AM
Why can't you add eventlistener to sprite? You can add the same listener to different sprites even.
Then use event.target to get the sprite which dispatched the event.
Because it throws an error saying the sprite is static and you can't add a eventlistener :/
edit: I want to change the fill colour of the sprite, that's why I need to access the sprite and not the movieclip. Don't know why I said alpha as an example since I can just change the movieclips alpha :S
Dazzer
October 26th, 2007, 09:26 AM
Then don't declare your sprite as static. Static variables can only be accessed by static functions.
Felixz
October 27th, 2007, 11:49 AM
Could u show more of ur code?
Best would be the way u instantiate those sprites and what error u get
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.