Jump to content
Search Community

SWFLoader, rawContent, Custom Class

frankrue test
Moderator Tag

Recommended Posts

Hello!

 

We are using the SWFLoader in LoaderMax. The code is in multiple files and strung together between numerous other classes and extensions, so I can't quite post the whole mess (plus an NDA is required), so I'll try to summarize.

 

My developers and I have a framework—built on Flex 4.6 via ANT—that loads up child SWFs ("Assets"). These Assets are also built on Flex 4.6 via ANT. The Assets, at times, load from a shared repository of like-classed Assets for common elements, like a common Background class (extended from Asset). All of these classes use the SWFLoader to do this.

 

If we run an Asset, locally, by itself in Flash Player, it works itself AND successfully loads its child Assets without a problem.

 

If we run the framework, it loads the same Asset successfully, but is unable to load the child Asset, and is unable to cast the child Asset as an Asset (it can only be seen as ContentDisplay from the SWFLoader, though even that doesn't actually display on-screen successfully).

 

The loader is not reporting any errors—the only error we can narrow down is immediately upon casting the rawContent as an Asset—this returns null to the local variable, and we are unable to do anything with the content at that point. Again: this ONLY happens when we attempt to do all of this in the framework.

 

We have tried setting the LoaderContext manually—that does not seem to do the trick, but, frankly, I don't even know what the LoaderContext can be set to apart from things like "_context.applicationDomain = ApplicationDomain.currentDomain;" and "_context.securityDomain = SecurityDomain.currentDomain;"...

 

Hopefully this makes sense.

 

Is there any insight on how to get rawContent to cast as a more specific, custom class without returning null? Why is this working when there is only *one* nested SWFLoader, but not a grandchild SWFLoader?

Link to comment
Share on other sites

It sounds like maybe a security error. LoaderMax tries to load assets in the most permissive way first, but if Flash squawks because of a security error, LoaderMax automatically falls back to a less permissive way of loading which means the rawContent will be a Loader instance. Again, that's all due to the way Flash imposes security restrictions and it has nothing to do directly with LoaderMax, nor can it be circumvented. Have you tried testing to see if the rawContent or content is a Loader instance? Have you listened for SECURITY_ERRORs? Are you subloading from another domain or maybe one file is local while the other is on the network? Do you have a crossdomain.xml file in place?

Link to comment
Share on other sites

Thanks for the reply.

 

We are using 'use-network="false"' in all of our mxmlc compilations of SWFs—initially, a security error was thrown as a result of this very problem. That security error (a native Flash Player Debugger error) is no longer thrown. We do have a listener set up for the LoaderMax.SECURITY_ERROR, but it is never thrown.

 

If I attempt to do anything with the rawContent, it "squawks" at me saying that I'm attempting to implicitly convert Background (which happens to be the accurate custom class name) into Asset (another custom class used as a parameter in the function attempted). This *appears* to mean that it recognizes rawContent as a particular custom class. However, if I attempt to cast "rawContent as Asset", it simply makes that local variable null. Background *IS*, in fact, an extension of Asset, so this should not be a problem in casting.

 

I am attempting to build an extremely stripped-down version for upload here, so you can look at the problem more specifically. Forgive the awful descriptions!

 

Any other thoughts?

Link to comment
Share on other sites

For some reason, it sounds like the Flash Player is disagreeing with you - background is NOT an Asset. This might be caused by you loading them into different ApplicationDomains or something. Think of it like different buckets. The classes might be named the same, but to Flash, they're from different buckets, so if you try casting an object that extends Bucket A Assset to be a Bucket B Asset, it'll return null. You must make sure you're referencing the SAME exact Asset class from the same ApplicationDomain.

Link to comment
Share on other sites

I was able to rebuild the project in a simplified form. The attached demonstrates much of what we're attempting to do. We use ANT with MXMLC to compile our Flash AS files, and that may, in theory, be a part of the problem.

 

However... This sample works fine. You'll not in the "Child.as" file in the Assets folder that we've commented out the standard ContentDisplay addChild methodology and, below that, cast the rawContent as a Sprite (from which Grandchild is extended), and then added that Sprite.

 

All works fine.

 

Something that we're doing in our more complex version is breaking this behavior. It's good to know that the simplified version is working, though. That gives me hope! :P

Link to comment
Share on other sites

SOLVED.

 

Turns out it was definitely an ApplicationDomain problem. Unfortunately, I had misread the attribute names between LoaderMax and SWFLoader. I was using "defaultContext" in SWFLoader, when, in fact "context" should be used. The attribute "defaultContext" is specifically for LoaderMax (queue), NOT for SWFLoader. Thus, all of our experiments with the "defaultContext" in SWFLoader were for naught.

 

Yay.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...