Jurgen,
I believe the problem here is that you are setting up a metadata tag on 
your class in actionscript which is not needed and I think it was said 
that Event meta tags are ignored by the compiler in ActionScript 
classes.  Someone here can clear that up for us.  I am not sure why, but 
it is only needed on MXML when setting up an event.  Because you are 
extending your class as an EventDispatcher, you only just need to 
dispatch the event you are setting up.

package components
{
import flash.events.Event;
public class MyClass extends EventDispatcher
{
    public static const MY_EVENT:String = "myEvent";
   
    private function myFunction():void
    {
        dispatchEvent(new Event(MyClass.MY_EVENT));
    }
}
}

THEN you can instantiate a MyClass variable and add an event listener:
            var mine:MyClass = new MyClass();
            mine.addEventListener(MyClass.MY_EVENT,someHandlerFunction);

The code assist is trying to show you the events on the event dispatcher 
and there really is just the two by default (activate and deactivate).
Don't ask me why though.  I always set up my Event types as constant 
vars on my class, so I know I need to access them off my class name.
This should work the same way for custom Events also.

Maybe an adobe flex expert can explain this better than I, but that is 
my understanding.

Regards,
Tony

P.S. ( you were borrowing (some call it hijacking) another thread and I 
think it was getting missed.)

Jurgen Wrote: >>>>>>>>>>>>>>>>>>>>>>>
There seems to be an issue using a custom class' event metadata in an
addEventListener statement. Here is an example:

package com.example
{

import flash.events.EventDispatcher;

[Event(name="myEvent", type="flash.events.Event")]

public class MyClass extends EventDispatcher
{

// class code

private function myFunction():void
{
dispatchEvent(new Event("myEvent"));
}

}

}

When using an instance of that class and creating an addEventListener in
code (not using it with MXML tags) Flex Builder's code assist lists the
event, but splits it apart and shows it as Event.MY_EVENT.

That of course throws a compiler error.

Is this by design and how would we work with an event in a custom class
using the [Event...] metatag?

I haven't checked to see if this is different with a custom event. I'll
check on that next, but I wanted to see if anyone has run into this
problem before.

Thanks,

Jurgen

Reply via email to