AssetLibrary.getMovieClip with multiple inheritance

Hi,

I work on a project in which we use a lot of SWF files. So I am using AssetLibrary to load and use movie clips. I create bundles with “openfl process”. But I encounter a problem with multiple inheritance in FLA file. I have configured a file with some movie clips :

  • One clip « ClipOne » which is configured to inherit directly from MovieClip
  • One clip « ClipTwo » which inherits from « ScriptedClip » which inherits from MovieClip

When I log the result of « getMovieClip » I have a little problem :

var test = library.getMovieClip("ClipOne") ;
trace(test) ;
> [object ClipOne]

var test = library.getMovieClip("ClipTwo") ;
trace(test) ;
> [object ScriptedClip]

Which is not really nice since we need to know which class is created. Do you have a solution about this ?

Second thing :
We have multiple swf files with same anim names ex : “AnimAttack”. When we process a swf file, it create a bundle with all classes in it with all class in package “package ;”. But if we have multiple movie clips with same names in different bundles, it can create conflicts.

Thanks

Is ClipTwo an “Export for ActionScript” class?

Can you tell if the instance is actually an instance of ClipTwo or is it for sure only an instance of ScriptedClip?

Currently you can workaround clips with the same names by using the “prefix” attribute when generating the bundle like “SWF1” which makes it “SWF1ClipTwo”, etc

Yes ClipTwo is an “Export for ActionScript”.

Yes again, the instance is actually an instance of ClipTwo because we can cast it. But in the project, at the point where we need the class name, we did not know which Clip we have requested. So I think that the clips have a good type but they are cast by AssetLibrary into their parent class. Is there a way to avoid that ?

Thanks for the tips with prefix. I’ll have a look at this but I think it will do the trick ! :slight_smile:

Hello !

We ended up with a solution for a part of the problem. We did not use Asset Library any more but we create the clip with Type.createInstance which is the same but we can create it using a string with Type.resolveClass.
For the prefix, it fixes the problem we encountered about that, Thanks.

But we have the following problem: In our project, we have MovieClips with other MovieClips inside. Imagine we have a ClipTwo (extends ScriptedClip) in ClipOne. When we create a ClipOne, the function new of MovieClip also creates his childs. But when we iterate on ClipOne children ClipTwo is typed into ScriptedClip. As we have multiple “ClipTwo” cases with different names in ClipOne we can’t know the class of his children. Can you help us about that ?

Do the generated classes look correct? ClipTwo exists and extends ScriptedClip? Both are “Export for ActionScript”?

Yes the generated classes looks correct ! They looks like other working clips.
Clip two exists in the generated bundle and extends ScriptedClip which extends AbstractClip which extend MovieClip (2 inheritance levels) and both are “Export for ActionSccript” in FLA.

Inside the generated classes are the child field properties using the correct “Export for ActionScript” class names as well? Like var firstChild:ClipOne, etc?

I’m not sure to understand the question. We have no field in generated classes. They look like this

package swf ; #if !flash
import openfl._internal.formats.swf.SWFLite;
import openfl.display.MovieClip;
import openfl.utils.Assets;

class ClipOne extends ScriptedClip {

	public function new () {
		super ();

		var swfLite = SWFLite.instances.get ("pyYR8eXMmeYwV2lejJ25");
		var symbol = swfLite.symbols.get (385);

		__fromSymbol (swfLite, cast symbol);
	}
}

#else
@:bind @:native("ClipOne ") class ClipOne extends ScriptedClip {
	public function new () {
		super ();
	}
}
#end

And ClipTwo:

package swf ; #if !flash
import openfl._internal.formats.swf.SWFLite;
import openfl.display.MovieClip;
import openfl.utils.Assets;

class ClipTwo extends AbstractClip {

	public function new () {
		super ();

		var swfLite = SWFLite.instances.get ("pyYR8eXMmeYwV2lejJ25");
		var symbol = swfLite.symbols.get (385);

		__fromSymbol (swfLite, cast symbol);
	}
}

#else
@:bind @:native("ClipTwo") class ClipTwo extends AbstractClip {
	public function new () {
		super ();
	}
}
#end

In the FLA file, there is an “instance” of ClipTwo into ClipOne clip (that’s what I mean buy “child”). So when we instanciate ClipOne, it creates a ClipTwo as a child of ClipOne.
And both ClipOne and ClipTwo are set to “Export for ActionScript” in the FLA file.

Oh maybe this is only in dev, we made changes so that named children would be present in the generated classes and if they were set to export for ActionScript they would be typed as their actual type instead of something generic like MovieClip

…but perhaps all that code only would help with clip.child.child references being typed and not actually change how those objects are constructed

Maybe the change is made in another openfl version ? Actually, I use 8.9.1
Or maybbe it’s only fixed using AssetLibbrary ?