I’m using this code to create a custom Event class:
package evt {
import flash.events.EventDispatcher;
import flash.events.Event;
public class OtherEvent extends Event {
public static const OTHER:String = "OtherEvent";
public var data:*;
public function OtherEvent(type:String, data:*) {
this.data = data;
super(type, true);
}
}
}
This lets me easily pass Objects that I will find in the data property, so that if I pass:
var d = {point:50};
dispatchEvent(new OtherEvent(OtherEvent.OTHER,d));
I will find the value of the key ‘point’ by writing evt.data.point.
The fact is that when I compile I receive a 1202 Error (Access to undefined property data in the package evt).
The strange thing is the following:
-
the error comes out only when I use the dot synthax:
eg.trace(evt.data.point); -
I get no error when I write:
trace(evt['data']['point']);
Could you help me understand what it happens and why?
EDIT: in Strict Mode the first one blocks anything. When not in Strict Mode I get ReferenceError #1075 variable evt::data is not defined.
Make sure that your event handler is set to receive an instance of “OtherEvent” rather than “Event”.
Also, rather than typing your “data” parameter with a wild-card, type it as an Object.
EDIT: Ah, I see now. I think your issue is that the class package is “evt” and the variable name in your event handler is also “evt”. It’s throwing an error to the compiler because it’s trying to access a package called “evt.data”. Simple fix – either change your class package to “events” (recommended) or change your variable name to something like “e”.