Jump to content
GreenSock

elmundo

Can not get class in SWF file

Recommended Posts

Hi everyone!

 

I'm trying to use LoaderMax class to load multiple SWF files. The problem is when all the swf files is loaded, (i hold them in an array), they all MovieClip type..

I use the SWF file as a graphic library so i need to get my assets from swf using SWFResource's method.

 

Before LoaderMax, i was using pushbutton engine resource loader and SWFResource class to get asset from a swf.

First, l was loading the resources, then getting to my SWFResource object

Like this:

 

//load the resources...

var swfRes:SWFResource = getSWFResource(resourceName);
var sprite:Sprite = swfRes.getExportedAsset(spriteName) as Sprite;

 

i need a similar way:

 

public function load():void {
		LoaderMax.activate([sWFLoader]);

		var url:Array = ["Doors.swf", "Animals.swf", "Xyz.swf"];

		_queue = LoaderMax.parse(_url, { maxConnections:1,
			                                          onProgress:progressHandler,
		                                                  onComplete:completeHandler,
						                  onChildComplete:childCompleteHandler 
							});
		_queue.load();
	}

private function completeHandler(e:LoaderEvent):void 
{
   trace("completeHandler");

   for each (var resourceInfo:ResourceFileInfo in _resourceInfoList) {
       _resources[resourceInfo.name] = LoaderMax.getContent(resourceInfo.file).rawContent;
   }
    //..and somehow i need to cast it SWFResource class
    var swfRes:SWFResource = _resources["Animals"] as SWFResource;
    var sprite:Sprite              =  swfRes.getExportedAsset("Cat_1") as Sprite
}

Link to comment
Share on other sites

I don't quite understand your question - are you saying you want to load things with LoaderMax and have it make them into SWFResource objects? From what I gather, SWFResource is a proprietary class from the PushButton engine, so that's not something LoaderMax could (or should) do. Of course you can load things with LoaderMax and then use them with PushButton, but as far as working with their SWFResource class, you'd need to talk to the PushButton folks about that. It's unrelated to LoaderMax.

 

Or did I misunderstand your question?

Link to comment
Share on other sites

i was using PBE's resourcemanager to get resource but when i tried to use bulk loader of PBE, there was some problems.

Then i decided to use LoaderMax for bulk loading. In my swf files, i use IsoClip -that i've written - which is extended MovieClip. Like this:

//
// C:\Users\omer\Desktop\_dev\restaurant\assets\swf\animals.swf\cat_1
//
package
{
import display.IsoClip;

public class cat_1 extends IsoClip
{
	public function cat_1();
}
}

 

When all swf file is loaded, i get them into my dictionary type object "_resources". Then i use this _resource to get my assets from swf files. Following code shows how i'm implementing this:

 

private function completeHandler(e:LoaderEvent):void 
{
	Logger.debug(this, "completeHandler", "Resource loading has been completed!");

	for each (var resourceInfo:ResourceFileInfo in _resourceInfoList) {
	          _resources[resourceInfo.name] = LoaderMax.getLoader(resourceInfo.file);
        }
}


public function getIsoClip(isoClipname:String, resourceName:String):IsoClip {
       var sefLoader:SWFLoader = _resources["Animals"] as swfLoader;
       var tempClass:Class = swfLoader.getClass("cat_1");

       var isoClip:IsoClip = IsoClip(new tempClass()); //Gettin error here!

       return isoClip;
}

 

After getting swf files into array, i use getIsoClip method to get isoClip asset but it gives:

Error #1034 Type Coercion failed cannot convert floor_cat_01@ae76df9 to display.IsoClip.

If i use default type (like MovieClip, Sprite, Sound ect..) there is no problem. But if i use a class that is written by me, i got this kind of errors..

 

i hope i could explain clearly this time. Thanks for help!

Link to comment
Share on other sites

Are you crossloading from another domain? Or are you running the swf locally and loading stuff over the network (which would force it into a separate SecurityDomain)? Sounds like an ApplicationDomain issue. Have you tried loading the swf into the currentDomain? See http://help.adobe.com/en_US/FlashPlatfo ... omain.html for info on Adobe's ApplicationDomain stuff. You can define your own LoaderContext for the SWFLoader using the "context" special property. Like

 

var loader:SWFLoader = new SWFLoader("1.swf", {context: new LoaderContext(true, ApplicationDomain.currentDomain)});

Link to comment
Share on other sites

  • 11 months later...

I came across the same issue when loading some assets from a local swf using the swfloader. I was also getting null results for each of the classes in the library of the loaded swf file even though all the domain/security permissions seemed fine.

 

What fixed the problem was adding the symbols on the stage of the remote swf. Once all the relevant symbols were dragged on the stage and the swf was loaded again, all the references magically worked. A bit weird but just in case someone else is facing the same issue, maybe this will solve the problem.

Link to comment
Share on other sites

Hi Vega,

 

Thank you very much for sharing your experience and suggestion. Hopefully that will help someone out of a jam.

 

I thought maybe a new version of the Flash Player introduced some new security restrictions.

I just did a test of instantiating a symbol from the library of an externally loaded swf in FP11.3 The external symbol used a custom class that extended MovieClip and I couldn't force any errors.

 

I'm curious, do you need to use the same work-around (placing assets on the stage) if you use a native AS3 Loader as opposed to a SWFLoader?

 

We'll keep our eyes open on this issue. Thanks again for offering the helpful suggestion.

 

-c

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