567 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+4 more
iamdok says

I’m building module loading into an OOP template and I’m having a problem with type casting.

I have 3 classes, Main, Modue & AboutModule. The AboutModule Class extends the Module Class. The About Clas consists of a Class and a linked fla with library assets. The document class of the fla is the AboutModule classpath.

The main class loads the swf file made from the AboutModule fla and attempts to cast it as type Module. This should be working seeing as the AboutModule extends the Module Class, but its giving me errors.

Here’s the swf loading complete casting operation:

                //got module
        private function moduleCompleteHandler(e : Event) : void
        {
            var loader : Loader = (e.currentTarget as LoaderInfo).loader;
            var module : Module = loader.content as Module; //returns null
                        //which means the AboutModule is not part of the Module type!

            trace("loader.content= " + loader.content); //AboutModule
            trace("module= " + module); //null

            contentHolder.addChild(module);
        }

Perhaps the confusion comes from the linking of the fla with its class. Maybe there is a better way of doing this. What is the normal way of linking library assets in swfs to OOP classes?

Any ideas?

Donagh

101 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
+1 more
PremiumFlash says

What error do You get?

567 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+4 more
iamdok says

Because I’ve used “as Module” instead of “Module()” casting method, it’s not throwing an error, but seeing as “null” is being returned, I am then getting the error on the last line, with the “addChild” – child cannot be null.

101 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
+1 more
PremiumFlash says

I see. I am not sure if the runtime environment can determine the loaded swf inheritance chain. You should cast to AboutModule or use Interface and cast to interface IModule.

Here is nice example of it: http://stackoverflow.com/questions/1554924/as3-loading-in-a-swf-as-a-custom-type

597 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+2 more
SparkyFlash says

Donaugh, try this one http://www.flashdevelop.org/community/viewtopic.php?f=9&t=5741&start=0

Export the MovieClips in swc, extend the classes, import them to your project and use them :) Should work just fine.

In your case, I understand where you coming from willing to cast the loaded swf all as Module, but I don’t like this approach. Try the above link, maybe you’ll find something useful for yourself.

5403 posts The Dude Abides
  • Located in United States
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
+9 more
CodingJack says

If your AboutModule class is the document class for your AboutModule fla, doesn’t it extend Sprite or MovieClip?

111 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $1,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
savorks says

This should working fine.

Maybe Module Class in Main.fla and Module Class in AboutModule.fla is refer to different Module.as file.

Make sure loader fla and loaded fla use same ClassPath, also be careful library asset Class name.

For example, if there is a asset in Main.fla library named Module(in Class name), it will cause something you encountered.

111 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $1,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
savorks says
If your AboutModule class is the document class for your AboutModule fla, doesn’t it extend Sprite or MovieClip?

If Module Class extends MovieClip or Sprite, it will works. :)

567 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+4 more
iamdok says

Thanks for the comments guys.

Yes the Module class extends Sprite Class.

It seems to be working now. I think there was a conflict in class names within the library assets, and I think Flash had also forgot my custom source path for custom classes. Or something!

I’ll make a post of the method in a couple of hours, but now have to run.

Thanks for the help.

Donagh.

5403 posts The Dude Abides
  • Located in United States
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
+9 more
CodingJack says
If your AboutModule class is the document class for your AboutModule fla, doesn’t it extend Sprite or MovieClip?
If Module Class extends MovieClip or Sprite, it will works. :)

That’s good to know :)

Donagh,. if you don’t create a class for something and export it for AS, it will inherits the root package. I’ve had the same conflict before, so I just renamed one of the clips like you did to solve it.

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by