ActionScript/Flex: Augment MouseEvents with extra information
Posted
by David Wolever
on Stack Overflow
See other posts from Stack Overflow
or by David Wolever
Published on 2010-03-12T19:10:26Z
Indexed on
2010/03/12
20:17 UTC
Read the original article
Hit count: 257
flex
|actionscript
I've got a business class, Spam
and the corresponding view class, SpamView
.
How can I augment MouseEvent
s coming out of SpamView
so the MouseEvent
s which come out of it contain a reference to the instance of Spam
which the SpamView
is displaying?
Here's how I'd like to use it:
class ViewContainer {
...
for each (spam in spams) {
addChild(new SpamView(spam));
...
function handleMouseMove(event:MouseEvent) {
if (event is SpamViewMouseEvent)
trace("The mouse is being moved over spam:", spam)
}
}
Thanks!
Things I've considered which don't work:
Adding event listeners to each
SpamView
: the book keeping (making sure that they are added/removed properly) is a pain.Using
event.target
: the event's target may be a child of theSpamView
(which isn't very useful)Listening for a
MouseEvent
, creating a newSpamViewMouseEvent
, copying all the fields over, then dispatching that: copying all the fields manually is also a pain.
© Stack Overflow or respective owner