Currently I’m developing a top down racing game in Flash for a client and thought I’d share the process that I’m going through. I’m not going to be posting any code, as it’s a client project, but I will try to explain how I worked various bits out so you can make your own ![]()
(more…)
Archive for August, 2008
Building a top down racing game Part 1
Tuesday, August 26th, 2008Custom Events in AS3
Sunday, August 3rd, 2008Just a quick one.
I’d been having troubles with Custom Events, specifically when they were being forwarded. An Event is dispatched, picked up by another class and then redispatched – the problem being that I’d always get a “cannot convert Event to MyCustomEvent” exception unless I typed the incoming event as an Event, which obviously meant that I lost the properties of the CustomEvent. Casting the Event to CustomEvent in the method gave the same result.
The solution is that you must always override the clone method in a custom event. Apparently, when an event is redispatched, it is cloned internally but with a new currentTarget. Something like:
override public function clone():Event
{
return new CustomEvent(type, bubbles, cancelable);
}
will fix the problem.