That's right, your move event
was conflicting with the one inherited from UIComponent.
When you write an event handler attribute
in MXML such as
mx:Label id=label move=label.text=event.x/
the MXML compiler autogenerates an event
handler that looks something like this:
function _label_moveHandler_(event:MouseEvent):void
{
label.text = event.x;
}
which the runtime then registers with
addEventListener().
The compiler gets the event class
(MouseEvent) from the metadata and uses it to strongly type the 'event'
parameter as the correct event subclass. If it simply declared 'event' as an Event,
you'd have to cast in order to be able to access subclass-specific event properties
such as x:
mx:Label id=label move=label.text=MouseEvent(event).x/
So on any particular components, the move
event needs to be associated with a single event subclass, such as MouseEvent
rather than YourEvent.
- Gordon
From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Jason Y. Kwong
Sent: Friday, March 10, 2006 10:33
AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Forced
to use MoveEvent?
Actually, never
mind. I think I figured it out. An event named move was
already declared previously by the framework. I guess I should just call
it something else. An interesting scenario, anyway...
On 3/10/06, Jason Y.
Kwong [EMAIL PROTECTED]
wrote:
My custom component broadcasts an event called move.
So I declare it in the MXML:
mx:Metadata
[Event(name=move,
type=flash.events.Event )]
/mx:Metadata
And then later dispatch it:
dispatchEvent(new Event(move));
But I get a runtime error when dispatching:
Type Coercion failed: cannot convert flash.events::[EMAIL PROTECTED]
to mx.events.MoveEvent
If I change my dispatch to this:
dispatchEvent(new MoveEvent(move));
It works fine. It also works fine if I rename the event to something
else. It looks like Flex expects any event named move to be
of type mx.Events.MoveEvent, no matter what you put in the Metadata tag.
Surely it wasn't meant to be this way?
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
Web site design development
Computer software development
Software design and development
Macromedia flex
Software development best practice
YAHOO! GROUPS LINKS
Visit your group "flexcoders" on the web.
To unsubscribe from this group, send an email to:[EMAIL PROTECTED]
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.