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: 102
Registered: ‎01-12-2011
My Device: Blackberry Playbook
My Carrier: DiGi twitter@TylorPin
Accepted Solution

noob question about SegmentedControl

Hi there I just started coding and while I'm using segmentedControl button, I doesn't know how to initiate a function when a segmentedcontrol option is pressed.

Untitled.jpg

As you can see, I want it when the "newest" is pressed, it instantiates a function which does what I want, but how do i do that? I'm just a beginner and still learning how to code any help I greatly appreciated.

Click "like" if my reply helps and click "Accept as Solution" if it solves your problem!

twitter @Twopinstudio
my vendor page https://appworld.blackberry.com/webstore/vendor/7126/?lang=en
Developer
Posts: 102
Registered: ‎01-12-2011
My Device: Blackberry Playbook
My Carrier: DiGi twitter@TylorPin

Re: noob question about SegmentedControl

I sort of created the event listener for SegmentedControl using button,addeventlistener(mouseevent,function) sample, and here's my code

 

Untitled2.jpg

 

and apparently this one didn't worked...any advice?

Click "like" if my reply helps and click "Accept as Solution" if it solves your problem!

twitter @Twopinstudio
my vendor page https://appworld.blackberry.com/webstore/vendor/7126/?lang=en
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: noob question about SegmentedControl

[ Edited ]

hey torres,

 

try using the Event.CHANGE instead and see what that yeilds. then check for the segemented control's selected index to see what button was pressed. on a side note for future reference, use the code option and copy and paste your code instead of taking screen shots of your code for faster help. images have to be approved by the moderators and can take time before we can see them publicly. 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: 117
Registered: ‎12-03-2010
My Device: Not Specified

Re: noob question about SegmentedControl

check the API doc, you should try listen Change Event instead of Mouse Event.

 

http://www.blackberry.com/developers/docs/airapi/1.0.0/qnx/ui/buttons/SegmentedControl.html#event:ch...

 

---------------------
a) If you like my response/post, please provide a Kudo (white star to the left).
b) If my post solved your problem please click on the Accept as Solution button.

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

Re: noob question about SegmentedControl

here is a sample code i just wrote up that should be able to help you figure out the segmented control:

 

SegmentedControlTest.as:

 

 

package
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;

import qnx.ui.buttons.SegmentedControl;
import qnx.ui.data.DataProvider;

[SWF(width="1024", height="600", backgroundColor="#E8E8E8", frameRate="30")]
public class SegmentedControlTest extends Sprite
{
private var mySegment:SegmentedControl;
private var buttonArray:Array;

public function SegmentedControlTest()
{
super();

// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;


buttonArray = [{label: "Black"}, {label: "Red"}, {label: "Yellow"}];

mySegment = new SegmentedControl();
mySegment.dataProvider = new DataProvider(buttonArray);
mySegment.setPosition(150,125);
mySegment.setSize(300,30);
mySegment.selectedIndex = 0;

mySegment.addEventListener(Event.CHANGE, onChange);

addChild(mySegment);


}

private function onChange(e:Event):void
{
trace("A change has been made.");

switch (e.currentTarget.selectedIndex)
{
case 0:

fillBackground(0x000000);

break;

case 1:

fillBackground(0xFF0000);

break;

case 2:

fillBackground(0xFFFF00);

break;

}
}

private function fillBackground(value:uint):void
{
this.graphics.clear();
this.graphics.beginFill(value);
this.graphics.drawRect(0,0,1024,600);
this.graphics.endFill();
}
}
}

 

Make sure to use the e.currentTarget to get your segmented control and then you can access any of its properites. also notice that onces you use the .selectedIndex in the code when you create it, it will dispatch the Event.CHANGE event. so just be ready for that. 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
Highlighted
Developer
Posts: 102
Registered: ‎01-12-2011
My Device: Blackberry Playbook
My Carrier: DiGi twitter@TylorPin

Re: noob question about SegmentedControl

Awsome! thanks JRab for the sample! using switch and e.currentevent.selectedindex worked perfectly! 

Click "like" if my reply helps and click "Accept as Solution" if it solves your problem!

twitter @Twopinstudio
my vendor page https://appworld.blackberry.com/webstore/vendor/7126/?lang=en