Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9095247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:33:01+00:00 2026-06-16T23:33:01+00:00

Given the following code: Class CEvent: public class CEvent extends Event { public static

  • 0

Given the following code:

Class CEvent:

public class CEvent extends Event
{
    public static const TYPE:String = "cEvent";

    private var m_strCode:String;
    public function get code():String
    {
        return m_strCode;
    }

    public function CEvent(pCode:String, bubbles:Boolean=false,
            cancelable:Boolean=false)
    {
        super(TYPE, bubbles, cancelable);
        m_strCode = pCode;
    }
}

Class A:

dispatchEvent(new CEvent(MY_CONST))

Class B:

m_a = new A();
m_a.addEventListener(CEvent.TYPE, onCEvent);
.
.
.

private function onCEvent(pEvent:CEvent):void
{
    switch (pEvent.code)
    {           
        case A.MY_CONST:
        dispatchEvent(pEvent);
    }
}

Class C:

m_b = new B();
m_b.addEventListener(CEvent.TYPE, onCEvent);
.
.
.
private function onCEvent(pEvent:CEvent):void
{ // breaks right here
}

I get this error when it breaks on class C, after dispatching it originally from Class A:

Error #1034: Type Coercion failed: cannot convert flash.events::Event@9861089 to
<path>.CEvent.

This doesn’t seem to make a lot of sense, and it seems to be going completely against the way inheritance works. Even if there were code in Adobe’s implementation of dispatchEvent() that specifically goes through and shaves off anything that’s been added through inheritance and just dispatches a “normal” Event instance, that should cause it to break in class B, not C.

Could someone please explain? Thanks.

Edit: By the way changing class B’s code to do this instead makes everything work just fine:

dispatchEvent(new CEvent(pEvent.code));

I still need to understand what the issue is though. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T23:33:03+00:00Added an answer on June 16, 2026 at 11:33 pm

    The error occurs because you have not implemented the clone() method in your custom event.

    When you re-dispatch an event (in your Class C), Flash clones the event instead of just re-dispatching the original event.

    The event that is re-dispatched therefore is a plain old Event object, because that’s what the default clone() method returns.

    In general, you should always implement a clone() method for your custom events. It’s pretty straight forward to do. In this case it should look something like this:

    override public function clone():Event
    {
        return new CEvent(m_strCode, bubbles, cancelable);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following Java code: public class Test { static private class MyThread extends
Given the following code: case class ChangeSet(field:String, from:Object, to:Object) private var changed:List[ChangeSet] = Nil
given the following code: public static class Helpers { private static Char[] myChars =
Given the following code : public class Game { private Map<String,Coordinate> m_myHashMap; ... //
Given the following code : public abstract class Participant { private String fullName; public
Given the following code: class C { static void m(String s) { ... }
Given the following code: public class A { static final long tooth = 1L;
Given the following code sample: public class WeirdStuff { public static int doSomething() {
Given the following code... [XmlType(Field)] public class SearchField { [XmlAttribute(alias)] public string Alias; [XmlAttribute(entity)]
Given the following code : import java.io.*; public class Main { public static void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.