Nested MovieClips with linkage names

I have an FLA with library assets. it has a movie clip with the linkage class “Child”, and another linked via “Parent”. Child is a child of parent. in the generated hx definitions Parent.child is a MovieClip. I can cast child to a Child with no issues (awesome!) but is there any reason why the definition doesn’t say the specific type?

If you use <library path="Assets/library.swf" preload="true" generate="true" /> we generate Haxe classes matching your “Export for ActionScript” classes, so new Parent () would work. This way includes the types for child types as well, so parent.child would be typed to the class type for Child.

When you use Assets.getMovieClip it does not use generated class types, so accessing children works through a generic getChildByName interface and is not strictly typed

Unfortunately I’m not seeing this behavior. I’ve got preload=“true” generate=“true”. My Parent library asset contains a child with the linkage Child, but I can see the _generated class has a child property of type MovieClip.

as I said. I can successfully cast it to type child, so it definitely is a Child.

Oh, currently this only works if the child is also Export for ActionScript

Child is set to export for action script, I took a pic of the library but forgot to add it. and the child truly is of type Child. so this is only really saving me a cast call. I’m just trying to better understand how openfl handles swfs

trace (new Parent().child);//[object Child]

the class headers in _generated:

class Child extends MovieClip {
...

and

class Parent extends MovieClip {
    
    public var child(default, null):openfl.display.MovieClip;
    ...

I’m using openfl 7.0.0 on haxe 3.4.4

Sounds like I’m experiencing some unexpected behavior, I’ll write an issue on github

is anyone else able to get typed children in this scenario?

I just tried a simple test, I have a SWF with a symbol called “ParentTest”, inside is an instance of a symbol called “ChildTest”, with a name of “child”. Both are “Export for ActionScript”

The library is using a tag like this:

<library path="library.swf" generate="true" preload="true" />

Here’s my sample code:

package;


import openfl.display.Sprite;
import openfl.utils.Assets;


class Main extends Sprite {
	
	
	public function new () {
		
		super ();
		
		var parent = new ParentTest ();
		trace (Type.getClassName (Type.getClass (parent.child)));
		
	}
	
	
}

…it works here. I check “_generated” and found both “ChildTest.hx” and “ParentTest.hx”, and parentTest.child is properly flagged as type ChildTest

I think we should consider generating the classes with the separate openfl process command (which lets you pre-process SWFs) and consider generating class names for all of the non-exported symbols (like Symbol01, etc) for better code completion, but those are future improvements

weird… I’m not sure what I’m doing wrong but my generated files look different. I wrote an issue in the openfl github repo, yesterday.

When I saw yours was working, I thought maybe “_generated” was lying to me, and that maybe my IDE was throwing errors rather than openFL. So I went 1 step further, and put a MovieClip inside my Child asset, name subchild. I bypassed my IDE and built the following code in terminal using opefl test project.xml flash -debug

trace(new Parent().child.subchild);// openfl.display.MovieClip has no field subchild

and got an error, whereas this was successful

trace(cast(new Parent().child, Child).subchild);// [object MovieClip]

for now I’ll just keep casting my vars