I want to adjust the width of DropDownList control in flex 4. I could do it by editing the skinclass and setting the PopupAnchor's Property "popUpWidthMatchesAnchorWidth" to false, but in my application I have to do it using actionscript.
You could set the typicalItem property of the DropDownList to the currently selected item.
From Flex Examples:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/01/21/resizing-a-spark-dropdownlist-control-to-match-the-currently-selected-item-in-flex-4/ -->
<s:Application name="Spark_DropDownList_typicalItem_test"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:DropDownList id="cb"
labelField="name"
typicalItem="{cb.selectedItem}"
requireSelection="true"
left="20" top="20">
<s:dataProvider>
<s:ArrayList>
<fx:Object name="Baltimore Orioles" abbr="BAL" />
<fx:Object name="Boston Red Sox" abbr="BOS" />
<fx:Object name="Chicago White Sox" abbr="CWS" />
<fx:Object name="Cleveland Indians" abbr="CLE" />
<fx:Object name="Detroit Tigers" abbr="DET" />
<fx:Object name="Kansas City Royals" abbr="KC" />
<fx:Object name="Los Angeles Angels of Anaheim" abbr="LAA" />
<fx:Object name="Minnesota Twins" abbr="MIN" />
<fx:Object name="New York Yankees" abbr="NYY" />
<fx:Object name="Oakland Athletics" abbr="OAK" />
<fx:Object name="Seattle Mariners" abbr="SEA" />
<fx:Object name="Tampa Bay Devil Rays" abbr="TB" />
<fx:Object name="Texas Rangers" abbr="TEX" />
<fx:Object name="Toronto Blue Jays" abbr="TOR" />
</s:ArrayList>
</s:dataProvider>
</s:DropDownList>
</s:Application>
thanks a lot for all responders. here i give the code which is used to clip the width of the dropdown.
package
{
import spark.components.DropDownList;
import mx.controls.Alert;
import spark.components.PopUpAnchor;
import mx.collections.IList;
import spark.components.ComboBox;
public class customDDList extends DropDownList
{
[SkinPart(popUpWidthMatchesAnchorWidth)]
public var popUp:PopUpAnchor ;
public function customDDList():void
{
super();
}
override protected function partAdded(partName:String, instance:Object):void
{
super.partAdded(partName, instance);
if (partName == "popUp")
{
instance.popUpWidthMatchesAnchorWidth = false;
}
}
public override function set dataProvider(value:IList):void
{
super.dataProvider = value;
}
}
}
You might as well create another skin for the DropDownList component and set the popUpWidthMatchesAnchorWidth property to false on the PopUpAnchor skin part:
<s:PopUpAnchor id="popUp"
displayPopUp.normal="false" displayPopUp.open="true" includeIn="open"
left="0" right="0" top="0" bottom="0"
itemDestructionPolicy="auto"
popUpPosition="below"
popUpWidthMatchesAnchorWidth="false" >
Related
I have one array of about 10 items and an array collection of about 200 items. The array collection will contain the first 10 items somewhere in there.
I would like to filter the array collection and order it to only show the items in the first array and in the order the first array lists them in.
<s:ArrayCollection id="baseballCardCollection" >
<fx:Object name="Bill"/>
<fx:Object name="Jill"/>
<fx:Object name="Phil"/>
<fx:Object name="Luke"/>
<fx:Object name="Duke"/>
<fx:Object name="Zach"/>
<fx:Object name="John"/>
<fx:Object name="Don"/>
<fx:Object name="Ron"/>
<fx:Object name="Anne"/>
<fx:Object name="Mark"/>
<fx:Object name="Clark"/>
</s:ArrayCollection>
Filter and sort in order by:
<fx:Array>
<fx:String>Zach</fx:String>
<fx:String>Anne</fx:String>
<fx:String>John</fx:String>
<fx:String>Mark</fx:String>
<fx:String>Luke</fx:String>
</fx:Array>
Goal:
<s:ArrayCollection id="baseballCardCollection" >
<fx:Object name="Zach"/>
<fx:Object name="Anne"/>
<fx:Object name="John"/>
<fx:Object name="Mark"/>
<fx:Object name="Luke"/>
</s:ArrayCollection>
You need to apply filter function for arraycollection then put your logic into filter function. Item will be available in arraycollection if filter function return TRUE else item will removed from arraycollection but still avaliable in ArrayCollection.source property ie baseballCardCollection.source
<fx:Script>
<![CDATA[
import mx.collections.Sort;
import mx.collections.SortField;
import mx.events.FlexEvent;
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
fitlerByPersonArray();
sortItemsByName();
}
private function fitlerByPersonArray():void {
baseballCardCollection.filterFunction = filterByPersonAndAddOrder;
baseballCardCollection.refresh()
}
private function sortItemsByName():void{
var srt:Sort = new Sort();
var orderField:SortField = new SortField("order");
orderField.numeric = true;
srt.fields = [orderField]; //Order by
baseballCardCollection.sort = srt;
baseballCardCollection.refresh();
}
private function filterByPersonAndAddOrder(item:Object):Boolean
{
var index:int = personArray.indexOf(item.name);
if(index > -1 ){
item.order = index; //Create new property called Order then sort with the help of order property
return true;
}
return false;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:ArrayCollection id="baseballCardCollection" >
<fx:Object name="Bill"/>
<fx:Object name="Jill"/>
<fx:Object name="Phil"/>
<fx:Object name="Luke"/>
<fx:Object name="Duke"/>
<fx:Object name="Zach"/>
<fx:Object name="John"/>
<fx:Object name="Don"/>
<fx:Object name="Ron"/>
<fx:Object name="Anne"/>
<fx:Object name="Mark"/>
<fx:Object name="Clark"/>
</s:ArrayCollection>
<fx:Array id="personArray">
<fx:String>Zach</fx:String>
<fx:String>Anne</fx:String>
<fx:String>John</fx:String>
<fx:String>Mark</fx:String>
<fx:String>Luke</fx:String>
</fx:Array>
</fx:Declarations>
<s:List dataProvider="{baseballCardCollection}" labelField="name" width="200" height="400">
</s:List>
sorry for my poor English.
I seached for hours but I couldn't find any solution for my problem.
I want to navigate my view to another from getting name of view from arrayList in DataProvider.
How can I get the clicked item's url and navigate as View.
Thanks..
<s:List id="listMenu" top="0" bottom="0" left="0" right="0" height="100%" width="100%"
click="navigator.pushView(listMenu.url as View)">
<s:dataProvider>
<s:ArrayList>
<fx:Object name="Title1" detail="Detail1" src="#Embed('../media/graphics/credit-card.png')" url="View1" />
<fx:Object name="Title2 Sorgulama" detail="Detail2" src="#Embed('../media/graphics/IMEI.png')" url="View2" />
</s:ArrayList>
</s:dataProvider>
<s:itemRenderer>
<fx:Component>
<s:IconItemRenderer labelField="name" messageField="detail" iconField="src" iconWidth="64" iconHeight="64" height="68" />
</fx:Component>
</s:itemRenderer>
Here you go -
assets/icons/FB.png:
assets/icons/GG.png:
views/Home.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">
<fx:Script>
<![CDATA[
import mx.core.BitmapAsset;
import mx.events.FlexEvent;
import spark.components.SplitViewNavigator;
import spark.components.ViewNavigator;
import spark.core.SpriteVisualElement;
import spark.events.IndexChangeEvent;
[Embed(source="assets/icons/FB.png")]
private static const FB_CLASS:Class;
[Embed(source="assets/icons/GG.png")]
private static const GG_CLASS:Class;
private static const FB_ICON:BitmapAsset = new FB_CLASS() as BitmapAsset;
private static const GG_ICON:BitmapAsset = new GG_CLASS() as BitmapAsset;
protected function handleChange(event:IndexChangeEvent):void {
var item:Object = login.selectedItem;
navigator.pushView(item.view, item.str);
}
]]>
</fx:Script>
<s:List width="100%" height="100%" id="login" change="handleChange(event);">
<s:dataProvider>
<s:ArrayCollection>
<fx:Object icon="{FB_ICON}" view="{FB}" label="Play at" msg="Facebook.com" />
<fx:Object icon="{GG_ICON}" view="{GG}" label="Play at" msg="Google+" />
</s:ArrayCollection>
</s:dataProvider>
<s:itemRenderer>
<fx:Component>
<s:IconItemRenderer labelField="label" iconField="icon" messageField="msg"/>
</fx:Component>
</s:itemRenderer>
</s:List>
</s:View>
App.mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:ViewNavigatorApplication
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
firstView="views.Home">
</s:ViewNavigatorApplication>
The views/FB.mxml and views/GG.mxml referenced above - to be created by yourself ;-)
I am learning Adobe Air and want to get the current selected item in the spinner list I have created, however every time I use selectedItem I keep getting the same value over and over, no matter what option I select. I am trying to make an application for the Playbook and this this my SpinnerList code:
<s:SpinnerListContainer x="10" y="279" width="325" height="266">
<s:SpinnerList width="69" height="100%" enabled="true" labelField="data" selectedIndex="1" id="From">
<s:ArrayList>
<fx:Object data="Time"></fx:Object>
<fx:Object data="KM"></fx:Object>
<fx:Object data="Miles"></fx:Object>
</s:ArrayList>
</s:SpinnerList>
</s:SpinnerListContainer>
No matter what, 'KM' is always shows as the selected item when it is not. This is what I have in the script tags:
var selected = From.selectedItem;
How can I fix this?
Thank you
Using 4.6 SDK this works for me:
<?xml version="1.0" encoding="utf-8"?>
<s:View title="HomeView"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
import spark.events.IndexChangeEvent;
protected function From_changeHandler(event : IndexChangeEvent) : void
{
somewhereToDisplaySelected.text = From.selectedItem.data;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:SpinnerListContainer height="266"
width="325"
x="10"
y="279">
<s:SpinnerList change="From_changeHandler(event)"
enabled="true"
height="100%"
id="From"
labelField="data"
selectedIndex="1"
width="69">
<s:ArrayList>
<fx:Object data="Time">
</fx:Object>
<fx:Object data="KM">
</fx:Object>
<fx:Object data="Miles">
</fx:Object>
</s:ArrayList>
</s:SpinnerList>
</s:SpinnerListContainer>
<s:TextInput id="somewhereToDisplaySelected"/>
</s:View>
I'm building a mobile app, using spark list control. When user tap on a list item, i want it to navigate to that correspondence page
<s:List id="list" width="100%" height="100%" labelField=" label">
<s:dataProvider>
<s:ArrayList>
<fx:Object label="Page One" />
<fx:Object label="Page Two" />
<fx:Object label="Page Three" />
<fx:Object label="Page Four" />
</s:ArrayList>
</s:dataProvider>
</s:List>
how do i code it so that when user tap on item label="Page One" it will navigate to PageOneView.mxml and if it tap on "Page Two" it will go to PageTwoView.mxml and so on.
thanks
The List should dispatch a change event. In that change event handler you can push the new view onto the view stack:
if(list.selectedIndex == 0){
navigator.pushView(viewOne);
} else if (list.selectedIndex == 1){
navigator.pushView(viewtwo);
} else if
etc...
I like the switch statement here as you can default to an action,
<?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="HomeView">
<fx:Script>
<![CDATA[
import spark.events.IndexChangeEvent;
protected function list_changeHandler(event:IndexChangeEvent):void
{
switch(list.selectedItem.label)
{
case "Page One":
{
navigator.pushView(pageOne);
break;
}
case "Page Two":
{
navigator.pushView(pageTwo);
break;
}
case "Page Three":
{
navigator.pushView(pageThree);
break;
}
case "Page Four":
{
navigator.pushView(pageFour);
break;
}
default:
{
navigator.pushView(pageOne);
break;
}
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:List id="list" width="100%" height="100%" change="list_changeHandler(event)"
labelField="label">
<s:dataProvider>
<s:ArrayList>
<fx:Object label="Page One"/>
<fx:Object label="Page Two"/>
<fx:Object label="Page Three"/>
<fx:Object label="Page Four"/>
</s:ArrayList>
</s:dataProvider>
</s:List>
</s:View>
Just a different way, suits my logic, created in Flash Builder 4.6.
Jacko
I have a list that as an arraylist as a dataprovider.It has an inline item renderer thet has image control. The click event doesn't work for the image ctrl.The code looks like this
<s:ArrayList id="allActionsArrList">
<fx:Object click="showList('Portlet')" source="#Embed('images/bpc1.jpg')" />
<fx:Object click="showList('Pages')" source="#Embed('images/Tab.png')" />
<fx:Object click="smsClick()" source="#Embed('images/launchpad_tel.png')" />
<fx:Object click="logoutImg_clickHandler(event)" source="#Embed('images/logoutS.swf')" />
</s:ArrayList>
<s:List id="actionStripList" bottom="0" width="100%" borderColor="black"
borderVisible="true" contentBackgroundAlpha="0" dataProvider="{allActionsArrList}"
useVirtualLayout="false">
<s:layout>
<s:TileLayout/>
</s:layout>
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer width="100%" height="40">
<mx:Image buttonMode="true" horizontalCenter="0"
width="40" height="40" source="{data.source}" click="{data.click}"/>
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
Any idea.Thanks in advance!
1.You may do something like this:
<fx:Object clickHandler="{showList}" clickParams="{['Portlet']}" source="#Embed('images/bpc1.jpg')" />
<fx:Object clickHandler="{showList}" clickParams="{['Pages']}" source="#Embed('images/Tab.png')" />
<fx:Object clickHandler="{smsClick}" clickParams="{[]}" source="#Embed('images/launchpad_tel.png')" />
<fx:Object clickHandler="{logoutImg_clickHandler}" clickParams="{[]}" source="#Embed('images/logoutS.swf')"/>
<mx:Image buttonMode="true" horizontalCenter="0" width="40" height="40" source="{data.source}" click="data.clickHandler.apply(this, data.clickParams)"/>
Here you possibly should take care of this object (info)
But I'd used the 2nd variant.
2.Another variant is to define some attribute (id for example) for your Object items. Then you can use switch statement in your inline itemRenderer and call different listeners depending on data.id.