1

I have implemented a new class that extends MovieClip. It's name is base.MovieClipWithDelays ("base" here is a package name).

My scene contains such an object named Blah. In Symbol Properties I checked Export for ActionScript and Export in first frame checkboxes. I set Class Name as T_Idle_0. And I specified it's Base class as base.MovieClipWithDelays.

The problem is that following code leads to the Type Error:

var dob:DisplayObject = getChild("Blah");
trace("SuperClass = " + getQualifiedSuperclassName(dob));
return MovieClipWithDelays(dob);

it outputs:

SuperClass = base::MovieClipWithDelays
TypeError: Error #1034: Type Coercion failed: cannot convert T_Idle_0@1ec59e9 to base.MovieClipWithDelays.

As you can see, it's superclass name is OK. Nevertheless, it fails to downcast it. How is it possible and how do I workaround it?

Bogdan Vasilescu
  • 407
  • 4
  • 22
Nick
  • 3,205
  • 9
  • 57
  • 108
  • Update: if I add debugging line trace("Is = " + (dob is base.MovieClipWithDelays)); it says "Is = false".... – Nick Nov 01 '11 at 10:50
  • 1
    are you using a single SWF, or using multiple SWFs? – Josha Nov 01 '11 at 11:05
  • What does `getQualifiedClassName` return? – Pranav Hosangadi Nov 01 '11 at 11:39
  • > are you using a single SWF, or using multiple SWFs? I use multiple SWFs. When I use single SWF, it works great. But when scene mentioned is loaded from another SWF, it fails to downcast. – Nick Nov 01 '11 at 11:49

1 Answers1

-1

You cannot set the base class of a library MovieClip to a custom class. You can either set it to Sprite or MovieClip. To do what you want to do, you have two solutions:

1 . Manage everything (drawing, etc.) from your MovieClipWithDelays class. i.e. don't make it depend on a library object.

Or:

2 . Make your MovieClipWithDelays wraps a MovieClip instance.

var libraryMC:MovieClip = new SomeLibraryMovieClip();
var customMc:MovieClipWithDelays = new MovieClipWithDelays(libraryMC);

Then within MovieClipWithDelays, you'll need to have some function and properties to handle the wrapped MovieClip.

laurent
  • 88,262
  • 77
  • 290
  • 428
  • 1
    Afraid this answer is false; you can set a custom class as base class (I have done this successfully many times). The custom class should still inherit from Sprite or MovieClip. – Josha Nov 01 '11 at 11:04
  • I never got that working, so I've always assumed it had to be a built-in ActionScript class. – laurent Nov 01 '11 at 11:07
  • I'm not so experienced, but as I read from Colin Moock's book "Essential ActionScript 3.0", it is OK to have a custom base class. I think the problem has different origin. When I use single SWF, it works great. But when scene (that contains that "Blah" object) is loaded from another SWF, it fails to downcast. – Nick Nov 01 '11 at 11:56