-
Eventlistener to sprite in loop?
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:
PHP Code:
private function hoverSprite(event:MouseEvent)
{
spritename.alpha = 0.5;
}
Because then only the last looped sprite will change alpha then.
-
Ronze
Hey
Fortunatly the event carries the event target - that's a path to the object that dispatched the event. So in your code, just do like this:
Code:
private function hoverSprite(event:MouseEvent)
{
event.target.alpha = 0.5;
}
Should work, but haven't tested it
-
Originally Posted by Ronze
Hey
Fortunatly the event carries the event target - that's a path to the object that dispatched the event. So in your code, just do like this:
Code:
private function hoverSprite(event:MouseEvent)
{
event.target.alpha = 0.5;
}
Should work, but haven't tested it
Ok, alpha was an bad example. Because I can just change the alpha of the movieclip. What I really need to do is to change the sprites fill colour, that's why I need to acces the sprite itself and not the movieclip. Sorry
-
Ronze
Hmmm... I don't understand. The sprites inside the different movieclips must have the same name, as you make them in a loop.
Therefore it's just to say:
Code:
event.target.spritename
to target the sprite. Here spritename is offcourse the name you give it in the loop. If you still have questions, post your code.
-
Originally Posted by Ronze
Hmmm... I don't understand. The sprites inside the different movieclips must have the same name, as you make them in a loop.
Therefore it's just to say:
Code:
event.target.spritename
to target the sprite. Here spritename is offcourse the name you give it in the loop. If you still have questions, post your code.
Thanks for the help. I kinda missunderstood a lot of stuff ^^ That's why you got confused when I tried to explain. I think I solved it now. Thanks again
-
Ronze
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|