One problem you have in your script is that you are not actually creating a
toggleSwitch in your code.
It should be something like
var tog:ToggleSwitch = new ToggleSwitch;
You have some options for assigning the skin.
If you are creating a class reference in the style section, such as
s|ToggleSwitch.myTog
{
skinClass : ClassReference("skins.MyToggleSwitchSkin");
}
You can assign the class reference using styleName
tog.styleName = “myTog” or tog.setStyle("styleName", "myTog”) (I am not sure
which is preferred, but both variations worked)
If you are not using the class reference, you can just assign the skinClass
tog.setStyle("skinClass", skins.MyToggleSwitchSkin);
> On Apr 27, 2015, at 4:07 AM, WelshAndy [via Apache Flex Development]
> <[email protected]> wrote:
>
> Hi Om,
> Thanks. Unfortunately, that skinClass suggestion didnt work :( Hope its
> appropriate to post the following code - Ive reduced it to the minimum:
>
> CustomToggle.mxml
>
> <?xml version="1.0" encoding="utf-8"?>
> <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
> xmlns:s="library://ns.adobe.com/flex/spark"
> creationComplete="view1_creationCompleteHandler(event)">
> <fx:Style>
> @namespace s "library://ns.adobe.com/flex/spark";
> myTog
> {
> skinClass:
> ClassReference("skins.MyToggleSwitchSkin");
> }
> </fx:Style>
> <fx:Script>
>
> <![CDATA[
> import mx.events.FlexEvent;
> import skins.MyToggleSwitchSkin;
> protected function
> view1_creationCompleteHandler(event:FlexEvent):void
> {
> var myTog:skins.MyToggleSwitchSkin = new
> MyToggleSwitchSkin();
> group.addElement(myTog);
>
> }
> ]]>
>
>
> </fx:Script>
> <s:VGroup id="group" top="30" />
> </s:View>
>
> and this is MyToggleSwitchSkin.as
>
> package skins
> {
> import spark.skins.mobile.ToggleSwitchSkin;
> public class MyToggleSwitchSkin extends ToggleSwitchSkin
> {
> public function MyToggleSwitchSkin()
> {
> super();
> selectedLabel="Yes";
> unselectedLabel="No";
> }
> }
> }
>
> Hope thats okay to post. As its unlikely that Im the first person to need to
> add custom toggle labels via code, Im guessing Im going about this in
> completely the wrong way! Ready to be enlightened...
> Thanks
>
>
> If you reply to this email, your message will be added to the discussion
> below:
> http://apache-flex-development.2333347.n4.nabble.com/Custom-ToggleSwitch-in-code-tp46201p46206.html
> To start a new topic under Apache Flex Development, email
> [email protected]
> To unsubscribe from Apache Flex Development, click here.
> NAML
--
View this message in context:
http://apache-flex-development.2333347.n4.nabble.com/Custom-ToggleSwitch-in-code-tp46201p46234.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.