Can I add a custom property to an starling sprite?

108 views Asked by At

Can I add a custom property to an starling sprite. I can do that in flash movieclip for eg myMc:MovieClip=new MovieClip(); myMc.myCustomProperty="abc"; can we do anything like this on starling sprite too or there is any alternative for it?

2

There are 2 answers

0
Lukasz 'Severiaan' Grela On

MovieClip is dynamic class that's why you can do it, if you need starling sprite with your custom properties then extend it and create your own implementation.

0
Ashley Stanbridge On

It is not possible to add custom properties as you have described for MovieClips in Native Flash because this class isn't dynamic. You can however override the Sprite class and add any custom properties you like.

package
{
    import starling.display.Sprite;

    public class CustomSprite extends Sprite
    {
        public var customProperty:String;
    }
}

You could also declare your new custom class as dynamic so you can add any properties you want without having to declare them, although this isn't good practice.