Create a uiasset
var uiAsset = new egret.gui.UIAsset(); uiAsset.source = "bgImage";
Add uiasset to skinnablecontainer
var container = new egret.gui.SkinnableContainer(); container.addElement(uiAsset);
After adding the container to the stage, the uiasset is not displayed. Why?
Now I checked the skinnablecontainer code and found that
public addElement(element:IVisualElement):IVisualElement { return this._getCurrentContentGroup().addElement(element);}public _getCurrentContentGroup():Group { if (this.contentGroup == null) { if (this._placeHolderGroup == null) { this._placeHolderGroup = new Group(); this._placeHolderGroup.visible = false; this._addToDisplayList(<DisplayObject><any>this._placeHolderGroup); } this._placeHolderGroup.addEventListener( ElementExistenceEvent.ELEMENT_ADD, this._contentGroup_elementAddedHandler, this); this._placeHolderGroup.addEventListener( ElementExistenceEvent.ELEMENT_REMOVE, this._contentGroup_elementRemovedHandler, this); return this._placeHolderGroup; } else { return this.contentGroup; }}
The addelement of skinnablecontainer is added to _ placeholdergroup if there is no contentgroup by default, while the default value of placeholdergroup is false. If contentgroup is found in partadded, the children of placeholdergroup is placed in contentgroup.
If there is no contentgroup in the skin, the subitem of all addelement of skinnablecontainer will not be displayed..
We give the container a skin.
VaR Container = new Egret. gui. skinnablecontainer (); container. skinname = testskin; container. addelement (uiasset); // Skin Class testskin extends Egret. gui. skin {private contentgroup: Egret. gui. group; Public get skinparts () {return ["contentgroup"]} Constructor () {super ();} public createchildren (): void {super. createchildren (); var group = new Egret. gui. group (); this. contentgroup = group; this. addelement (Group );}}
There is a contentgroup in testskin, so that the uiasset will be displayed.
Some Issues about skinnablecontainer in Gui