Skip to main content
Ned Murphy
Legend
January 18, 2013
Answered

CustomEvent class issue

  • January 18, 2013
  • 1 reply
  • 1688 views

I make use of a CustomEvent class, one which I believe is standard since when I went to create it at one point, I swear Flash filled in all of the code for it before I could paste it in.  I use it to have swf's that are loaded by a main file capable of dispatching an event with some data to go with it.  The code for the class is shown below at the bottom.

The CustomEvent class file is planted in a com folder structure that is defined in my classpath for Flash

It works fine for me when it works, but it seems like anytime I start a new directory/collection of files for a new/divergent revision of the main file, the published swf's produce errors with respect to the CustomEvent class when I try to load into the main file...

TypeError: Error #1034: Type Coercion failed: cannot convert com.path::CustomEvent@80ac1c1 to CustomEvent.
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at loadedswf_fla::MainTimeline/frame23()

What ends up fixing this is publishing the files again within their new folder structure.

I have always been under the impression that once you publish an swf it burns in the code that was used in its creation and no longer requires the AS class files that were used in creating it.  But this one seems to defy that. 

Do you know why this happens and what might be done to not have to remedy it by republishing? There are quite a few of them which makes it a bit of a pain each time a new variation comes about.

Here is the class file code:

package com.path

{
     import flash.events.Event;

 


     public class CustomEvent extends Event
     {
          public var params:Object;


          public function CustomEvent(type:String, params:Object, bubbles:Boolean = false, cancelable:Boolean = false)
          {
               super(type, bubbles, cancelable);
               this.params = params;
          }


          public override function clone():Event
          {
               return new CustomEvent(type, params, bubbles, cancelable);
          }
         
          public override function toString():String
          {
               return formatToString("CustomEvent", "params", "type", "bubbles", "cancelable", "eventPhase");
          }
     }
}

This topic has been closed for replies.
Correct answer kglad

What would be the ideal setup for having the file planted in a common .com folder?

you mean a com folder that has class files shared among different projects?

Now to confuse regarding locations of the class file...

There is no copy of the CustomEvent class in the folder that contains the flas that create the swfs, nor in the folder that contains the swfs.

Because I have used this CustomEvent class for various projects, I keep a copy of it in my immediate classpath folder.  So based on what you said, there is a chance that the first CustomEvent file in the classpath is what gets seen when I publish rather than the one in the com.path folder

if you have an identically named CustomEvent in a default class path (eg, assigned in the advanced actionscript settings panel's source path), the same problem occurs.  that class (in the default class path) will be used instead of the one from the import statement.

This same folder contains the "com" folder wherein via the "path" it has another copy of the same class file.  This is because this project has a set of custom-made class files, and the CustomEvent class has been grouped with them in that folder named "com" with the files in the same "path" so that all of the project class files have common location for sharing them with other developers when things change.

any same named class files that flash can access are potentially problematic.  to debug your setup, use a different trace() statement in the constructor of the various same-named problematic class files.  that will show you which class file flash is using.

While I don't think it matters in this case, there is also a com folder that sits in the main project folder as a repository for the various class files for the whole project.  I say I don't think it matters because it is a folder that is parallel to the folder that contains the flas and another folder that contains the swfs that the fla's publish.

it's only irrelevant if flash does not know these files exist.  if any of the files are in its class path, you have a potential problem.

One thing that adds to my own confusion is that none of the other class files that live with the CustomEvent class in the com/path folder(s) have this issue... though when those get run it is usually the main file being compiled when it is run, not a saved swf using the CustomEvent class. 

that's expected under certain circumstances.  one, there's no name collision.  two, the same-named class files are document class files. and there are possibly other situations.

The main file imports the project classes using

import com.path.*;

Since that local com/path folder sits parallel to the main file (same parent folder), I am imagining it is really using the local com/path versions and not the one intended in the classpath.

use the trace suggestion above to see what flash is using.

Could it be that the main file is using a different copy of the class file when I test and regardless that it is an identically coded file, it is not the same physical file and things fail as they do?

if you use one class file to create an instance, in another class/scope, that instance may no longer be the same class type used in that different scope, even though they're both CustomEvent class types.  ie, you'll get that unable to coerce CustomEvent to CustomEvent error.

I still don't understand why the file seems to be looking for the CustomEvent class after it has been published.  When the final product is put in place, it will not have the class files anywhere in sight, so I expect that the swf's should have everything they need published into them.

correct, swf files contain the compiled code.  after a swf successfully compiles it doesn't matter where it's located (with respect to the actionscript used) and it doesn't matter what or where the class files are that were used to publish it.  if you publish a swf that has no compile-time errors, running it will trigger no compile-time errors.  but, you may encounter runtime errors.

1 reply

kglad
Community Expert
Community Expert
January 18, 2013

if you have the above class in com.path and your have another class named CustomEvent in the directory with your swf (with no package specification), even though you import com.path.CustomEvent, flash will use the CustomEvent class in the default directory.  it won't use the com.path.CustomEvent class.

when you move to a new directory, there is probably no CustomEvent class in that directory and all works as you expect.  if there is a CustomEvent class in the default directory with the swf, when you direct flash to create that (com.path.CustomEvent) file, it fills in the code from that (the default directory CustomEvent)  class.

Ned Murphy
Legend
January 18, 2013

What would be the ideal setup for having the file planted in a common .com folder?

Now to confuse regarding locations of the class file...

There is no copy of the CustomEvent class in the folder that contains the flas that create the swfs, nor in the folder that contains the swfs.

Because I have used this CustomEvent class for various projects, I keep a copy of it in my immediate classpath folder.  So based on what you said, there is a chance that the first CustomEvent file in the classpath is what gets seen when I publish rather than the one in the com.path folder

This same folder contains the "com" folder wherein via the "path" it has another copy of the same class file.  This is because this project has a set of custom-made class files, and the CustomEvent class has been grouped with them in that folder named "com" with the files in the same "path" so that all of the project class files have common location for sharing them with other developers when things change.

While I don't think it matters in this case, there is also a com folder that sits in the main project folder as a repository for the various class files for the whole project.  I say I don't think it matters because it is a folder that is parallel to the folder that contains the flas and another folder that contains the swfs that the fla's publish.

One thing that adds to my own confusion is that none of the other class files that live with the CustomEvent class in the com/path folder(s) have this issue... though when those get run it is usually the main file being compiled when it is run, not a saved swf using the CustomEvent class. 

The main file imports the project classes using

import com.path.*;

Since that local com/path folder sits parallel to the main file (same parent folder), I am imagining it is really using the local com/path versions and not the one intended in the classpath.

Could it be that the main file is using a different copy of the class file when I test and regardless that it is an identically coded file, it is not the same physical file and things fail as they do?

I still don't understand why the file seems to be looking for the CustomEvent class after it has been published.  When the final product is put in place, it will not have the class files anywhere in sight, so I expect that the swf's should have everything they need published into them.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
January 18, 2013

What would be the ideal setup for having the file planted in a common .com folder?

you mean a com folder that has class files shared among different projects?

Now to confuse regarding locations of the class file...

There is no copy of the CustomEvent class in the folder that contains the flas that create the swfs, nor in the folder that contains the swfs.

Because I have used this CustomEvent class for various projects, I keep a copy of it in my immediate classpath folder.  So based on what you said, there is a chance that the first CustomEvent file in the classpath is what gets seen when I publish rather than the one in the com.path folder

if you have an identically named CustomEvent in a default class path (eg, assigned in the advanced actionscript settings panel's source path), the same problem occurs.  that class (in the default class path) will be used instead of the one from the import statement.

This same folder contains the "com" folder wherein via the "path" it has another copy of the same class file.  This is because this project has a set of custom-made class files, and the CustomEvent class has been grouped with them in that folder named "com" with the files in the same "path" so that all of the project class files have common location for sharing them with other developers when things change.

any same named class files that flash can access are potentially problematic.  to debug your setup, use a different trace() statement in the constructor of the various same-named problematic class files.  that will show you which class file flash is using.

While I don't think it matters in this case, there is also a com folder that sits in the main project folder as a repository for the various class files for the whole project.  I say I don't think it matters because it is a folder that is parallel to the folder that contains the flas and another folder that contains the swfs that the fla's publish.

it's only irrelevant if flash does not know these files exist.  if any of the files are in its class path, you have a potential problem.

One thing that adds to my own confusion is that none of the other class files that live with the CustomEvent class in the com/path folder(s) have this issue... though when those get run it is usually the main file being compiled when it is run, not a saved swf using the CustomEvent class. 

that's expected under certain circumstances.  one, there's no name collision.  two, the same-named class files are document class files. and there are possibly other situations.

The main file imports the project classes using

import com.path.*;

Since that local com/path folder sits parallel to the main file (same parent folder), I am imagining it is really using the local com/path versions and not the one intended in the classpath.

use the trace suggestion above to see what flash is using.

Could it be that the main file is using a different copy of the class file when I test and regardless that it is an identically coded file, it is not the same physical file and things fail as they do?

if you use one class file to create an instance, in another class/scope, that instance may no longer be the same class type used in that different scope, even though they're both CustomEvent class types.  ie, you'll get that unable to coerce CustomEvent to CustomEvent error.

I still don't understand why the file seems to be looking for the CustomEvent class after it has been published.  When the final product is put in place, it will not have the class files anywhere in sight, so I expect that the swf's should have everything they need published into them.

correct, swf files contain the compiled code.  after a swf successfully compiles it doesn't matter where it's located (with respect to the actionscript used) and it doesn't matter what or where the class files are that were used to publish it.  if you publish a swf that has no compile-time errors, running it will trigger no compile-time errors.  but, you may encounter runtime errors.