1
votes

I am building an application within Flex 4.6, which uses a custom skin on the main <s:Application>. This skin has several components inside of it which I would like to access from the main application.

I tried using this.skin.getChildByName("<name of component within skin>"), but it gave me a runtime error.

How can I access a component within the skin from the main application?

1

1 Answers

2
votes

IF the component of the Skin is not exposed as a skinPart, then accessing it that way is a violation of encapsulation rules and generally defeats the benefit of the Flex Skinning Spark model which separates business logic from visual display.

That said, you can access the skin using something like this:

// for a SparkSkin
var skinAsSparkSkin : SparkSkin = this.skin as SparkSkin;
// for a MobileSkin
var skinAsMobileSkin : MobileSkin = this.skin as MobileSkin;
// for your custom skin type
var skinAsCustomSkin : MyCustomSkin = this.skin as MyCustomSkin;

Once you have access to the skin, you can access public variables inside the skin using something like this:

trace(skinAsSparkSkin.myVaribleInsideSkin);

For components you create in the skin in MXML, which are not skin parts, they will be public variables and you can access them by the ID you defined in the MXML code:

In Skin:

<s:List id="myList"/>

In Component Class:

trace(skinAsSparkSkin.myList);