Sprite Class with dynamic/array access


I have question about haxe language. Ideally I want a class which extend Sprite with dynamic acess (like MovieClip in AS3).
Is it possible?

As an alternative I want to create class with array access something like this:

class MySprite extends Sprite
    public inline function get(code:String) {
        return this.getChildByName(code); // get


class MySprite extends Sprite
	private var _properties = new Map<String, Any>();

    @:op([]) public function propRead(code:String)
        return _properties[code]; // get
    @:op([]) public function propWrite(code:String, value:Any)
        _properties[code] = value; // set
        return value;

But it does not work as I expected.

I have own gui constructor from json which is generated from .FLA. I can construct MySprite and add fields aka child names so I can write something like:

var mySprite:MySprite = Gui.construct("scene1");
mySprite.childName.childName.childName.textFieldName.text = "message";
mySprite['childName']['childName']['childName']['textFieldName'].text = "message";

Thx for advices!

You’re in luck! The recent OpenFL 9.2 update includes a new ChildAccess abstract that should allow you to access children dynamically.

But I need it for Starling Sprite)
Is it a haxe trick that I can repeat?

ChildAccess is intended only for OpenFL display objects. You didn’t mention Starling in your original post.

You could try copying the code for ChildAccess into a new class and make some tweaks to imports and things, and you might be able to get it to work in Starling instead of OpenFL. Starling display objects have many of the same properties as OpenFL display objects, so a lot of the properties defined on ChildAccess should just work with changes to imports. However, Starling has some different properties too, so some may need to be removed, and some new ones may need to be added.

Ok, thx!
I think about common solution on haxe language layer. For example make extended class as dynamic or something else. Yes, ChildAccess is a good solution.