Second child access in swf-lite without breaking C++?

The only way I fount to access the second child of a movieclip imported from a swf using swf-lite is to use Reflect.field but this breaks C++ of course. Is possible to use swf-lite without breaking C++ target?

You should be able to access them directly with current versions:

FirstChild.SecondChild.x = 100;

The catch is that after the first child, it’s typed only as DisplayObject. If you need to use something special (such as accessing TextField features) then you need to cast:

cast (FirstChild.SecondChild, TextField).text = "Hello!";

This was needed to keep the typed nature of the API, so that you can set x, y and other standard properties without issue (since these are getters and setters)

Let me know how it goes :slight_smile:

If you call the first element a child then I mean “third child”.
I already can do this:


what I cannot do is this:


I get an error of “has no field”

I’m using:
haxelib swf version: 2.0.3
openfl version: 3.2.2

So can I avoid reflection to use more than 2 childs and not brake C++?

Does FirstChild.SecondChild.getChildByName ("ThirdChild") work?

I should set up a test for this… :slight_smile:

It works! :smiley:
With this super dirty syntax you can get to the fourth child (in this example) without using Reflection:

var myBuriedClip:DisplayObjectContainer = 
			swfData.firstChild.getChildByName("secondChild"), DisplayObjectContainer)
			.getChildByName("thirdChild"), DisplayObjectContainer)
			.getChildByName("fourthChild"), DisplayObjectContainer);

Oh! I know why :smile:

Dynamic access is enabled currently for MovieClip only. That means that our types are degrading on step at a time:

var ref = FirstChild; // typed as MovieClip
ref = FirstChild.SecondChild; // typed as DisplayObject
ref = FirstChild.SecondChild.ThirdChild; // typed as Dynamic, and null (or crash)

I’m not sure if this should be just noted when working with SWF assets, or if there should be some other system for this. We could make all DisplayObjects allow dynamic access, but I’m concerned that could create performance issues?

That sounds like a question for Nicolas Cannasse