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
Related
in my mxml part I have
<s:layout.landscape>
<s:HorizontalLayout />
</s:layout.landscape>
<s:layout.portrait>
<s:VerticalLayout />
</s:layout.portrait>
after these tags i have couple of components, for example
<s:Button label="button 1"/>
<s:Button label="button 2"/>
what I would like to do is change the order of these components once a portrait or landscape state is entered. For example in portrait I have vertical layout button 1 followed by button 2
and in landscape I have horizontal layout where button2 is followed by button 1.
You can use this.swapElements(button1,button2);
Example: -
<?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"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600" currentState="landscape">
<s:states>
<s:State name="landscape"/>
<s:State name="portrait"/>
</s:states>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import spark.events.IndexChangeEvent;
protected function dropdownlist1_changeHandler(event:IndexChangeEvent):void
{
// TODO Auto-generated method stub
if(event.target.selectedIndex == 0)
{
this.currentState = event.target.dataProvider[0];
this.swapElements(button1,button2);
}
else
{
this.currentState = event.target.dataProvider[1];
this.swapElements(button2,button1);
}
}
]]>
</fx:Script>
<s:layout.landscape>
<s:HorizontalLayout />
</s:layout.landscape>
<s:layout.portrait>
<s:VerticalLayout />
</s:layout.portrait>
<s:DropDownList selectedIndex="0" change="dropdownlist1_changeHandler(event)">
<s:ArrayCollection>
<fx:String>landscape</fx:String>
<fx:String>portrait</fx:String>
</s:ArrayCollection>
</s:DropDownList>
<s:Button id="button1" label="button 1"/>
<s:Button id="button2" label="button 2"/>
</s:Application>
Hope this may help...
I'm using Adobe Flex Builder 4.5, and I'd like to create a vertical, scrollable list of panels for an AIR application. How do I do that?
A little something like this:
<fx:Declarations>
<s:ArrayCollection id="dp">
<fx:Object title="Panel A" content="content AAAAA" />
<fx:Object title="Panel B" />
<fx:Object title="Panel C" />
<fx:Object title="Panel D" />
</s:ArrayCollection>
</fx:Declarations>
<s:List dataProvider="{dp}" height="100%">
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer>
<s:Panel title="{data.title}">
<s:Label text="{data.content}" />
</s:Panel>
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
Doesn't matter whether you're in AIR or just Flex.
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 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" >
I have a TextInput inside a spark Item Renderer. I need to undo some behavior in a library I'm using by stopPropagation of the mouseDown and mouseUp event for the TextInput. However, I would like the TextInput itself to handle such events normally - otherwise the caret to cursor transitions don't seem to be properly handled. I'm ashamed to admit, I'm not sure how to do this - seems simple but I have been stuck on it for some time.
thank you!
Edit: ok, here's some code to explain what's going on (although it's completely unrelated from what I'm doing, so it's not an exact depiction of my specific situation). As I mentioned above I need to be able to stop the propagation of mouseDown and mouseUp from the TextInput to a component up the food chain - event.stopPropagation() in mouseDown and mouseUp for the TextInput does the trick. However, it messes up the caret / cursor handling for the TextInput itself. Try the code below with or without the event.stopPropagation() and you should see what I mean.
Main
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/03/19/using-a-custom-item-renderer-function-with-the-fxlist-control-in-flex-gumbo/ -->
<s:Application name="Spark_List_itemRendererFunction_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">
<fx:Script>
<![CDATA[
import mx.core.ClassFactory;
import spark.skins.spark.DefaultItemRenderer;
private function list_itemRendererFunc(item:Object):ClassFactory {
var cla:Class = DefaultItemRenderer;
switch (item.type) {
case "employee":
case "manager":
cla = EmployeeItemRenderer;
break;
default:
break;
}
return new ClassFactory(cla);
}
]]>
</fx:Script>
<s:List id="list"
labelField="name"
itemRendererFunction="list_itemRendererFunc"
horizontalCenter="0" verticalCenter="0">
<s:dataProvider>
<s:ArrayList>
<fx:Object name="Employee 1" type="employee" />
<fx:Object name="Employee 2" type="employee" />
<fx:Object name="Employee 3" type="employee" />
<fx:Object name="Employee 4" type="employee" />
<fx:Object name="Manager 1" type="manager" />
<fx:Object name="Manager 2" type="manager" />
<fx:Object name="Employee 5" type="employee" />
<fx:Object name="Manager 3" type="manager" />
<fx:Object name="Consultant 1" type="consultant" />
</s:ArrayList>
</s:dataProvider>
</s:List>
</s:Application>
and EmployeeItemRenderer.mxml
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/03/19/using-a-custom-item-renderer-function-with-the-fxlist-control-in-flex-gumbo/ -->
<s:ItemRenderer name="EmployeeItemRenderer"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true">
<fx:Script>
<![CDATA[
protected function TI_mouseDownHandler(event:MouseEvent):void
{
event.stopPropagation();
}
protected function TI_mouseUpHandler(event:MouseEvent):void
{
event.stopPropagation();
}
]]>
</fx:Script>
<s:HGroup>
<s:Label id="labelDisplay" left="4" right="4" top="4" bottom="4" />
<s:TextInput id="TI" mouseDown="TI_mouseDownHandler(event)" mouseUp="TI_mouseUpHandler(event)"/>
</s:HGroup>
</s:ItemRenderer>
Can you post what you've tried so far?
I think all you would need to do is register listeners for the mouseDown, mouseUp, and click events and then use http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/Event.html#stopPropagation() to stop the events from bubbling further from the currentTarget out to the parents, stopImmediatePropagation would stop the event from triggering listeners on the current object.
Shaun
PS I'll edit if you post some code and I can clarify.
OK, Sounds like this is only an issue for Flex 4.01 (thank you JAX). In such case I got what I wanted by stopping propagation on the mousedown event but not on the mouseUp. This is a very specific case that applies to my code, so I'm not sure if it'll be really useful for anyone else. I guess the interesting lesson for me, here, is that mouseUp is the event that is related to caret / system cursor management.