Jump to content
GreenSock

frank6

[SOLVED] Loading SWF with a custom document Class

Recommended Posts

Hi,

 

I have this swf which has a document Class extending a dynamic class named PageKernel and another swf with a document class named PageLoader. When the PageLoaded loads the Page, the page isn't playing has if there was a compile error. When I remove the document class PageKernel from the nested swf it works. Does anyone have an idea of what I am doing wrong ?

 

Thanks in advance !

Francis

Link to comment
Share on other sites

Are you using a unique ApplicationDomain when subloading the swf? If you're using the same ApplicationDomain, that would explain your problem because since you're using the same package/class name, one is overwriting the other in Flash. It is generally not recommended to use the same package and class name for swfs that are being subloaded. But if you use a unique ApplicationDomain, you should (in theory) be okay.

 

If you're still having trouble, feel free to post the two FLAs (and any support files) so that we can publish on our end and see what's going on. No need to post your production files - just something super simple is fine (even better actually).

Link to comment
Share on other sites

Thanks for the reply.

 

I tried to specified a different ApplicationDomain or use the current one but it is still not working. I am wondering what I am missing here. I've attached my test project to this post hoping I could get some help !

 

Thanks in advance !

Link to comment
Share on other sites

Ok.. I realised that I was wrong with the context property of the loader. I've been able to load my swf sucessfully and make it play but now the problem is that I can't access the Page object from the PageLoader. When I try to use the page variable in my onCompleteHandler function I get the error message :"Type Coercion failed: cannot convert com.test::Page@28001f81 to com.test.Page."

 

context = new LoaderContext(false, new ApplicationDomain(null))
		loader = new LoaderMax({onComplete:onCompleteHandler});		 
		pageLoader = new SWFLoader("page.swf",{name:"page",context:context, autoPlay:true, container:this});
		loader.append(pageLoader);
		loader.load();

 

Thanks again!

Link to comment
Share on other sites

Right, when you use a unique ApplicationDomain like that, Flash subloads those classes in the swf in their own sandbox of sorts. They don't map to any of the classes you have in your other sandbox. That's the whole point - to avoid conflicts. So you can't take the "Page" class from one sandbox and try forcing it to be cast as an instance of the "Page" class in the other sandbox.

 

The other thing that you were running into is that you added frame scripts to your Page.fla file (on an ActionScript layer on the timeline) which is totally fine, BUT those will be ignored completely if you subload the swf into the same ApplicationDomain as the parent which ALREADY HAS A PAGE CLASS. You can't have it both ways - either Flash uses the one that you have in your PageLoader.swf (which has no frame scripts) OR the one in your Page.swf. When you subloaded into the same ApplicationDomain, Flash was like "oh, that thing is a Page instance and I've already got that class right here...so I'll just use that constructor and move on..." (meaning it doesn't add any of the custom frame scripts that you put into your FLA).

 

I hope that makes sense. Flash is doing exactly what it is supposed to here, but I realize it can seem confusing with the whole ApplicationDomain thing. I'd suggest reading up on ApplicationDomain on Adobe's site or elsewhere to get your head wrapped around it.

 

By the way, you could add your frame scripts into the main Page.as class file - that way, you'd get consistent behavior across the board.

Link to comment
Share on other sites

Thank you I really appreciate. I like how you explained the concept it helped me to have a better understanding. So there is no possibility to use framescript in a subswf and trying to access it, right ? Is there any alternative ?

Link to comment
Share on other sites

I could make it work ! Thanks again!

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.
×