Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: ToggleSwitch in Flex

Cant you just add the control to the item containing "toggleSwitchContainer" instead of having another nested layer?

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: ToggleSwitch in Flex

[ Edited ]

@comantis: whoa you are absolutely right! you can do it that way. i missed that completely. here is a code i ran to confirm it for anyone else interested:

 

FlexTestHome.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"
title="Home" creationComplete="init()" xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import qnx.ui.buttons.ToggleSwitch;

private var toggleSwitch:ToggleSwitch;

private function init():void
{
toggleSwitch = new ToggleSwitch();
toggleSwitch.setSize(300,60);
toggleSwitchContainer.addChild(toggleSwitch);
}

]]>
</fx:Script>

<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:UIComponent id="toggleSwitchContainer" x="10" y="10" />
</s:View>

 

 

well played!

 

@johnp: switch the solution by going to Options > Not The Solution for my post above!

 

@jtegen: since the parent container (at least in my example) is a spark.component.View component, it only takes addElement methods and not addChild.

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
JohnPinkerton
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)

Re: ToggleSwitch in Flex

JRab, I don't know what I'm doing wrong, other than maybe because I have multiple states it's causing an issue? I've added includeIn="New" so that it is in the correct state.

 

 

import qnx.ui.buttons.ToggleSwitch;

 

private var toggleSwitch:ToggleSwitch;

 

In my init function

 

	toggleSwitch = new ToggleSwitch();
toggleSwitch.setSize(300,60);
toggleSwitch.selectedLabel = "One Fish";
toggleSwitch.defaultLabel = "Two Fish";
toggleSwitch.selected = false;
this.addChild(toggleSwitch);

 

In the form:

 

<mx:UIComponent id="toggleSwitchContainer" x="500" y="500" includeIn="New" />

 

No errors, installs to the simulator without issue. :smileysad:

 

 

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: ToggleSwitch in Flex

hey johnp,

 

no worries, heres the line you need to fix and you should be golden:

 

change this:

 

	this.addChild(toggleSwitch);

 

to this:

 

	toggleSwitchContainer.addChild(toggleSwitch);

 

let me know how it turns out. good luck!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
JohnPinkerton
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)

Re: ToggleSwitch in Flex

That didn't work either. I removed the background to be sure it wasn't causing issues, and still no dice. :smileysad:

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: ToggleSwitch in Flex

hey johnp,

 

thats strange. did you make sure to set the creationComplete attribute to init() ? maybe that function isnt running and is causing issues. so something like this:

 

 

<?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"
title="Home" creationComplete="init()" xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>

(...)

 

hope that clears it up. good luck!

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
JohnPinkerton
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)

Re: ToggleSwitch in Flex

Yeah, I have some other functions in my init function (swipe down for instance) and they're working.

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: ToggleSwitch in Flex

hey johnp,

 

is your debugger set to on (can you see traces via the trace() function)? if so add this line right after the toggleSwitchContainer.addChild() method:

 

 

private function init():void
{
toggleSwitch = new ToggleSwitch();
toggleSwitch.setSize(300,60);
toggleSwitch.selectedLabel = "One Fish";
toggleSwitch.defaultLabel = "Two Fish";
toggleSwitch.selected = false;

toggleSwitchContainer.addChild(toggleSwitch);

trace("toggleSwitchContainer.numChildren: " + toggleSwitchContainer.numChildren);
}

 

 

the trace should output this:

 

 

toggleSwitchContainer.numChildren: 1

 

good luck!

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
New Developer
comantis
Posts: 52
Registered: ‎02-15-2011
My Device: Not Specified

Re: ToggleSwitch in Flex

I can only think that some other UI element is covering up  the toggle button.  

Either that, or the simulator is not picking up your changes.  Maybe try doing a clean build, and deleting the app from the simulator and reloading it.  

 

Also try giving the toggleSwitchContainer a width and height

 

 

<mx:UIComponent width="80" height="180" id="toggleSwitchContainer" />

 Failing that, start with the sample Jrab gave, and progressively add in your code until you see it break again :smileyhappy:

 

Developer
JohnPinkerton
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)

Re: ToggleSwitch in Flex

<3 BlackBerry Developer Forums - everyone here is great!

 

I removed the size settings and applied them to the container. I also removed the: 

toggleSwitch.selected = false;

 

I uninstalled the project from the PlayBook simulator, gave it a fresh reboot (been a while since I've done that), removed the existing .bar file from the project - ran it fresh to the PlayBook and voila! There it sits in all it's glory!

 

You guys are great!