ActionScript 3.0 :: Set Selection Based On "selectedItem.label" Instead Of "selectedIndex"?
Jul 6, 2010
In a simplified version of my issue, I have a ComboBox called "cb". I can set its selectedIndex to 1 (corresponding with selectedItem.label of "Red") easily with:
cb.selectedIndex = 1
However, since "Red" may not always be at a selected index of 1, if another entry is placed before it in the list, I would MUCH rather base my code on selectedItem.label, since it will always be "Red."
How do I do this? I can at least trace the label's corresponding selection index with code like:
var frameSelect:Number = cb.selectedIndex; trace(frameSelect)
Do I need some sort of loop function? Or is there a simpler way? Can I define a variable at the very start of my code that figures out what the corresponding selection index of "Red" is on that particular day? I basically need
var frameSelect:Number = cb.[Index of whatever goes with the label of "Red"]
If it useful to you, what I am doing (on a simplifed scale) is using a combo box to change the color of a movie clip. The user can click on "Blue" or "Yellow" or "Red" in the comb box, and the movie clip changes color. However, I also need a simple button that only has one outcome ("Red") where the user clicks on the button and thus sets the selected index of the combobox directly to "Red." Like I said, I can do this quite easily using the selectedIndex parameter, but this means I would have to manually update my button's code each time a new color option was added. Not remotely ideal, since the actual implementation has hundreds of colors in arrays and there will be lots of buttons creating arrangements from different comboboxes.(Say one combobox is Colors, one is Shapes, and one is Size. The end goal is to let the user experiment as much as they want through dropdowns, OR click a button like "Small green circle" to go directly to a particular outcome.)
View 3 Replies
Similar Posts:
Mar 16, 2005
Ok I can't find any doco on this and it's driving me crazy. Anyone know how you specify the default value for the V2 ComboBox component based on the selectedItem when you don't know the selectedIndex? Here's my scenario:
I have a hardcoded combobox called "dd_names" with 50 names in it. I'm returning a dataset into Flash via a SQL query, and onload I need the dd_names dropdown to default to the value of the name returned in the dataset. So if the query returns "Tom" I need the dropdown to default to "Tom."
I tried setting dd_names.selectedItem = "Tom" and dd_names.value = "Tom" and these don't work. The ComboBox just defaults to the first item in the list.However, if I use the selectedIndex property and set dd_names.selectedIndex = 3, the ComboxBox doesn't default to the first item in the list but shows the appropriate item. This doesn't help because I don't know the selectedIndex being returned from the query - I only know the selectedItem. Anyone know how to do this??
View 4 Replies
Feb 8, 2012
I am unable to bind the selectedIndex public property of a spark DropDownList to it's original source in the view's presentation model.
For the purposes of replicating this issue with as few lines as possible I have two views, and one presentation model. The code follows.
Main.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
[code]...
Debugging the application I find that selectedIndex in the presentation model always remains at the default value assigned regardless of which item I selected from the DropDownList. For the sample code above this is -1.How can I bind the selectedIndex in the presentation model such that it is updated appropriately when the selected item DropDownList changes?
View 1 Replies
Sep 14, 2011
how I would go about to accomplish the following:
There should be 3 dropdown menus with predefined words
1. First menu has 3 predefined options
2. The second dropdown has 5 options.
3. The third dropdown has 3 options
--> Depending on which word is selected in dropdown #2, an img (of a total of 5 possibilities) is being displayed
In addition there is a dynamic textfield, where you can enter a name, which should then be displayed along with the img.
View 1 Replies
May 28, 2009
Here is what I'm trying to do. I have a sunroom product that is available with several different options. I have created images of every possible combination of options, and named the files like this:
DeckFurniture_NoVisor_ClearGlass_View1.jpg
Hot Tub_Visor_TintedGlass_View3.jpg
I want users to be able to choose their options, and have the appropriate picture be displayed. So to get the above image, they'd have to choose "Deck Furniture" "No Visor" "Clear Glass" and "View 1". Or to get the other one they'd choose "Hot Tub" "Yes Visor" "Tinted Glass" and "View 3"
It's not necessary to have it auto-update the image, so I was thinking they could choose their options and then click "Update", and that would in a sense pull up the correct filename from the options they've chosen. I'm not exactly sure how to tell Flash to change this master variable (the filename) whenever one of the sub-variables (pieces in the filename) change. Would I have to put a script on each option button telling it when it gets selected to change the master variable?
View 5 Replies
Jan 3, 2011
I am in the process of learning AS 3 and Flash on my own and currently using the Actionscript 3.0 Adobe Classroom in a book CS4 version. Having a problem with the Lesson Adendum if anyone has done it. This lession requires you to create two buttons. They both draw shapes on the stage. When one is clicked, it draws Rectangles on the stage following the mouse movement. When the other is clicked, it draws Ellipses instead. The problem I am having is that it just draws rectangles and not ellipses when the 2nd button is clicked. Would be greatful if someone could tell me what i am doirng wrong. Here is the code that I have so far. Apologize for the commented out code, I left it in to show what I have tried:
[Code]...
View 4 Replies
Jun 14, 2010
how do i change the item selected in a combobox selection based on a selection of a datagrid object?
View 2 Replies
Apr 6, 2009
I'm trying to allow users to download a song based on a radio button selection. And I've succeeded in getting the "save as" box to pop up, but for some reason, the file does not actually download and save after you hit the save button.
[Code]...
EDIT: Someone informed me that if the variables weren't defined OUTSIDE of the function then they would be garbage collected. I moved them outside but it is still behaving the same.
View 1 Replies
Oct 22, 2010
I'm trying to make a little program. It works right now by drawing the top shape to the dark gray area, where it then copies itself and changes color. The new shape can be re-dragged as well. What I want to do now is add a dynamic border when I click on the new object, I want the box to adjust to an appropriate size. And on mouse release I want the selection border to disappear on the new shape. I want the selection border to be dashed much like you find in many of Adobe's programs, if at all possible.
Attached is my .fla file
View 1 Replies
Mar 8, 2011
I have a simple TLF text box on stage. i want to be able to click some words in the text and based on the selection clicked got to some other place on a timeline or set a variable (not a link to an external web page).
sounds like it shout be simple but i cannot seem to find any information about it.
i seem to remember having done something similar years ago in as1 or as2.
View 3 Replies
Mar 29, 2012
Is it possible to show or hide a comboBox based off the selection made in another comboBox. I have been looking for documentation on this to no avail.
View 2 Replies
Nov 11, 2010
I never realized that fl.getDocumentDOM().selection doesn't retain the selection order... <sniff>. I was hoping to build relationships based on the order. I guess I took if for granted that tools like Maya and Max store the selection buffer in order of what was selected. I'm trying to avoid: Select Object, <Press 'Parent' Button>, Select Parent, <Press 'Parent' Button>
View 2 Replies
Sep 6, 2007
i am attaching a number of _mc (my_mc) with a for loop. Inside each my_mc is an input textfield (my_txt)I want to click on my_mc.my_txt and select the textfield .the following code allow this and i can enter text from the keyboard however I want to add text from a _mc keybooard on screen (here called myBtn_mc).As soon as I click on myBtn_mc of course I lose focus ... i have tried to use a variable (select) to keep scope&focus
View 6 Replies
Sep 26, 2010
I have an Array Collection as follows
var myArr:ArrayCollection = new ArrayCollection([
{label: "label1", data: "data1"},
{label: "label2", data: "data2"}]);
[Code]....
How to set the selected item for myDDL based on an item id(myID)? I tried something like:
selectedIndex = {myArr.getItemIndex(myID)}
View 1 Replies
Aug 14, 2009
In the code below, the presentedAlbumIndex is used to control the selectedIndex of the TileList. Item "five" is initially selected. Whenever the button is pressed the first item in the array is deleted, and the presentedAlbumIndex is decremented.
In theory, the selected index should stay with "five" every time the button is clicked (until "five" is itself deleted). It works this way for the first button press. However, on the 2nd button press the highlighting changes to "six" for some reason. Also, the TileList selectedIndex is always one behind.
I tried looking into ListBase and monitoring selectedIndex. It looks like the selectedIndex is updated initially to the correct index, but then it reverts back at some point to the correct index+1. I do not know why it's setting back.
It seems it's due to the fact that I am doing a data provider delete and index change in the same operation.
Is there some function in TileList I could override to keep selectedIndex up to date?
Steve
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
[Code]....
View 1 Replies
Apr 9, 2010
Is there something like selectedIndex for SkinnableDataContainer? It doesn't seem to be one of the available properties.
View 2 Replies
Mar 11, 2011
I have a simple button function that changes the selectedIndex on a view stack without using the menu bar component. I call the function from the click property on the button and pass an int as the index I want to jump to. When I had the code on the application MXML file everything worked fine. After moving my actionscript to a separate file, I get access of undefined property errors:
protected function changeView(index:int):void
{
myViewStack.selectedIndex = index;
[code].....
View 2 Replies
Nov 26, 2004
I have a simple button function that changes the selectedIndex on a view stack without using the menu bar component. I call the function from the click property on the button and pass an int as the index I want to jump to. When I had the code on the application MXML file everything worked fine. After moving my actionscript to a separate file, I get access of undefined property errors:
protected function changeView(index:int):void
{
myViewStack.selectedIndex = index;
}
How do I get the .as file to recognize the myViewStack component? Do I need to reference Main.MXML somewhere in the .as file? Thanks.
Here is the rest of my code:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
[code]....
And finally the .as files with the function in question:
import mx.containers.ViewStack;
protected function changeView(index:int, myViewStack:ViewStack):void
{
myViewStack.selectedIndex = index;
}
View 3 Replies
Jun 30, 2004
I am having a real problem with one of my components. I have a list object and I need to set the selectedIndex. Now I would think this would be easy, but it appears that for just this instance the selectedIndex property is read only. I have set the property for other instances, and I can read the property for this instance, but I cannot change it.
View 1 Replies
Feb 3, 2011
When using a dropdownlist in flex I'd like to know the exact index value when the prompt is initialized in it.
View 1 Replies
Sep 8, 2011
when i use nextSlide() and prevSlide(), which are executed when i click on two buttons. SelectedIndex works when i click on the elements in the List. What am i doing wrong? do i have to dispatch some events? Are there any tricks to doing it with buttons?This is my playlist class
public class Playlist extends List
{
private var dispatcher:Dispatcher;
[code]......
View 2 Replies
Dec 8, 2011
I have a viewstack, which contains 3 (at this moment just 1) customcomponents:
<s:Application xmlns:components="components.*">
<mx:ViewStack id="mainViewStack" x="76" y="90" width="800" height="400">
<components:Login />
[code].....
View 1 Replies
Apr 22, 2009
In lee's xml tutorial he uses the list component and the text area component but when he tested the swf he had to select the item befour the text field was populated.
i have set the selectedIndex to 0 but the data still does not load untill an item is selected.
View 2 Replies
Oct 15, 2009
i am working in Air application in Flex3 , i need know how to set "selectedItem" Property when we have 2 values like(data and label) label property to combobox selection, data value for our input.In (selectedItem="{stylename}") stylename will have "data" value but i need to set that "lable" property as selected value in combobox.Like if stylename is "checked" then the ComboBox selected item need to be "Checked".How to implement this in flex.
View 1 Replies
Apr 13, 2011
I"m using Flex 4 and an AdvancedDataGrid. I need to keep track of the previously selected item. I can't think of where to capture this though. In an itemClickHandler method, the grid's selectedItem value is already the current selected item.
View 2 Replies
Sep 10, 2011
I am making some simple project and I have problem with selectedItem. I have sth like this
<s:State name="Form" enterState="makesService.send()"/>
so when I enter this state I take makes from database and populate them to dropdownlist.
but I have also button and on click event I'm changing state to this Form and I want to select specific make from the dropdownlist but I can't. I'm not sure whether I'm doing sth wrong or the problem is that I'm selecting item just before the dropdownlist became populated.
e.x. List of make consist of Audi and BMW and when I click button I want to open this state Form in which this dropdownlist exist with selected value e.x. BMW.
View 1 Replies
Jun 21, 2007
I have a DataGrid bound to an XMLConnector and XMLDataSet. The XML data loads fine into the components. However, I cannot get the value of the selected index using: my_datagrid.selectedIndex
The call works fine if you use addItem to populate the grid.
Is there an issue being that the datagrid.selectedIndex parameter is bound to the XML components?
View 1 Replies
Jun 21, 2010
Isn't there a better way to accomplish this?[code]...
All I want to do is make sure that when I update the item that the comboBox is pointing to internally, that it's selectedIndex also update so that the label within the ComboBox reflects the new value.
View 1 Replies
Jul 23, 2004
I've got a combo box in my movie (called news_selector), whenever the selection of the combo box changes, I want to do something. Here's my code for the combobox so far...
Code:
on(change)
{
trace("News feed changed to: " +news_selector.selectedIndex);[code].....
The problem is that the news_selector.selectedIndex bit is showing as undefined in the debug window, and thusly the if/else statements are ignored completely.
View 1 Replies
Nov 13, 2008
I've got a combobox, cb, for which I need to programmatically set the selection. The combobox was populated by:
cd.addItem({data:"string1",label:"string1"});
cd.addItem({data:"string2",label:"string2"});
cd.addItem({data:"string3",label:"string3"});
Lets say I need to set the combobox to "string2",I've tried all of the following, none work:
cb.selectedItem("string2");
cb.selectedItem(data:"string2");
cb.selectedItem(label:"string2");
cb.selectedItem({data:"string2",label:"string2"});
The docs say selectedItem() is read/write but all the examples I can find are read only.
View 2 Replies