I created a button and assigned it's skin to RectangleSkin.
However when I later tried to know what skin I had assigned, in order to get the instance of it and change it's color values, I could not access it.
Eg. I tried using
button.backgroundSkin
but this does not give back the intended value I had assigned previously.
How to get the skin assigned to a button?
- Edited
This works for me. What value does it give back instead?
var skin = new RectangleSkin();
var button = new Button();
button.backgroundSkin = skin;
trace(button.backgroundSkin == skin); // true
addChild(button);
trace(button.backgroundSkin == skin); // true
button.validateNow();
trace(button.backgroundSkin == skin); // true
Ah.. I am not using validateNow(). I will try that.
You are not required to call validateNow()
, in this case. I just added that call to test that backgroundSkin
wasn't getting inadvertently cleared during validation.
I was trying to do something like this that was giving me error
var skin:RectangleSkin = button.backgroundSkin ;
I figured out I just needed a cast.
var skin:RectangleSkin = cast button.backgroundSkin ;