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
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)

Re: ToggleSwitch in Flex

Well, at least, it works on the Home stage - it's invisble on the New stage.

 

Hmmm...

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

Re: ToggleSwitch in Flex

hey johnp,

 

glad you got it working as a proof of concept. at least you know it works now! so for it only showing up in the Home stage, are you using view components or are you using states?

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
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)

Re: ToggleSwitch in Flex

I'm using states except for top swipe which is component.

 

I do have it set to includeIn="New" - which it doesn't display in, but when I set it to Home it does.

 

I started reading up but got distracted with some graphical elements I'm trying to finish up, sorry I don't have any other updates for you.

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

Re: ToggleSwitch in Flex

hey johnp,

 

dont sweat, i get distracted and digress all the time haha. question, are you running your project as an regular flex project or a mobile project? dont know if thats relavent but thought id ask. anyways my theory is as i think comantis has stated is something might be covering up your toggle switch. so try to set it with weird x and y values (the container) and see if that helps it show up. place it somewhere you know nothing else will be and place it there and see if it shows up.

 

below is a sample code i wrote up showing that it works using states. when you toggle it switches the states from "home" to "new" but keeps hte toggle visible in both views:

 

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" currentState="Home">
<fx:Script>
<![CDATA[
import qnx.ui.buttons.ToggleSwitch;

private var toggleSwitch:ToggleSwitch;

private function init():void
{
toggleSwitch = new ToggleSwitch();
toggleSwitch.setSize(300,60);
toggleSwitch.selectedLabel = "New";
toggleSwitch.defaultLabel = "Home";

toggleSwitch.addEventListener(Event.SELECT, onSelect);

toggleSwitchContainer.addChild(toggleSwitch);

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

private function onSelect(e:Event):void
{
if (e.target.selected)
{
currentState = ToggleSwitch(e.currentTarget).selectedLabel;
}
else
{
currentState = ToggleSwitch(e.currentTarget).defaultLabel;
}

this.title = currentState;
}

]]>
</fx:Script>

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

 

 

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
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)

Re: ToggleSwitch in Flex

I've tried different background, no background, random locations on top of other elements, off on it's own. I've tried colored background, I've tried it in all the states (only shows in Home).

 

This might be a hint to you: It displays fine in BOTH states of Home/New if I includeIn="Home, New"

 

Is your brain tickled yet? Mine's pickled! :smileytongue:

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

Re: ToggleSwitch in Flex

wow that really is strange lol. my next theory is are the states properly being switched? like is the "New" state active or is another state active. is there something else thats also just in the "New" state along with the mx.UIComponent? the icons you mentioned probably are but im just throwing up ideas at this point haha

 

ah also try to create a new flex mobile project. and try to run the sample app. maybe its your project that is causing the errors. that way we can weed more stuff 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
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)

Re: ToggleSwitch in Flex

I feel it has something to do with my init function.

 

If I set the set the currentState="New" in my Application it loads the slider just fine within the New state. However, setting the UIComponent to includeIn="Home" and not New while currentState is set to New, it does not render in Home.

 

To chance states I'm using a "round about" way to do it - I have a component to handle my swipe down nav, and I'm using FlexGlobals.topLevelApplication.currentState to change states as I couldn't get my custom event listeners to work properly so I gave up and went with that - which seems to work for not only changing state but I'm also able to call the functions from topLevelApplication.function()

 

 

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

Re: ToggleSwitch in Flex

that's weird. i tried running the code i posted in the previous post with the state switching via the toggle and then replaced the currentState with FlexGlobals.topLevelApplication.currentState and got the following error when i tried to toggle:

 

 

ArgumentError: Undefined state 'New'.

 

how are you setting the states in your app?

 

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
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)

Re: ToggleSwitch in Flex

Button:

<s:Button width="150" height="45" id="Home" label="Home" click="goHome()" skinClass="Skins.HomeBTNSkin" x="15" y="15"/>

 

goHome() function:

 

FlexGlobals.topLevelApplication.currentState = "Home";
Developer
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)

Re: ToggleSwitch in Flex

Messy way to get it to work also:

 

 

includeIn="Home, New" visible.Home="false"

 

Shows up fine in New. I'll rebuild everything tonight and see if I yield any different results. My init function just doesn't want that to load unless it is also loading in the state the app starts in.