how to set value and trigger function in flash - actionscript-3

hi so this is my first flash application i have two functions one a click handler to take you to the list page and a function to call the results is there any way in actionscript to pass values through variables like in php($)
what i need to do is to set the function off from the button that is pressed every button needs to supply a different value to the list to get results heres the two functions
protected function button_clickHandler_100():void
{
currentState='data';
}
protected function dataGrid_creationCompleteHandler(event:FlexEvent):void
{
getCitysResult.token = cityservice.getCitys(/* VALUE ENTERED HERE */);
}
<s:Button click="button_clickHandler_100()" id="button128" includeIn="europe" skinClass="components.englandButton" x="101" y="135"/>
<s:Button click="button_clickHandler_100()" id="button129" includeIn="europe" skinClass="components.denmarkButton" x="135" y="117"/>
<s:Button click="button_clickHandler_100()" id="button130" includeIn="europe" skinClass="components.polandButton" x="214" y="135"/>
<mx:DataGrid includeIn="data" x="28" y="10" id="dataGrid" creationComplete="dataGrid_creationCompleteHandler(event)" dataProvider="{getCitysResult.lastResult}" width="276" height="255">
<mx:columns>
<mx:DataGridColumn headerText="city" dataField="city"/>
</mx:columns>
</mx:DataGrid>
so for instance the vlaue that needs to be supplied is GB for button128 , PL for button130 ....
getCitys returns a list of citys and populates a datagrid according to a 2 letter code it is a php sevice
is there a way i could get the clickHandler to supply the value to getCitys function according to which button is pressed off the id of the button say

Related

Get value of editable GridColumn in flex

I have one datgrid with no. of columns like:
<s:DataGrid id="cpDataGrid" dataProvider="{arrList}">
<s:columns>
<mx:ArrayList>
<mx:source>
<s:GridColumn headerText="Name" dataField="name" editable="false"/>
<s:GridColumn headerText="Age" datafield="age" editable="false"/>
<s:GridColumn headerText="Test" dataField="test" editable="false" />
<s:GridColumn width="100" headerText="Result" dataField="result" >
</mx:source>
</mx:ArrayList>
</s:columns>
</s:DataGrid>
In the above datagrid result column is editable. I have make function when user done entering value in that column as following:
protected function onCreationCompleteHandler(event:FlexEvent):void
{
cpDataGrid.addEventListener(GridItemEditorEvent.GRID_ITEM_EDITOR_SESSION_SAVE, onSave);
}
private function onSave(event:GridItemEditorEvent):void
{
var name:String = event.currentTarget.selectedItem.name;
}
Now, I will get name and other field value when edit end. But i need Result text. Means Whatever user entered text in that field.
Like suppose user enter 50 in result column then how can i got that value?
Any help will greatly appreciated.
For spark.DataGrid you need to create custom class based on spark.DataGrid and override method endItemEditorSession. In it you can access DataGrid's property itemEditorInstance.
If you would use mx.DataGrid, you could use DataGridEvent.ITEM_EDIT_END event in combination with itemEditorInstance property of DataGrid.
// register listener
cpDataGrid.addEventListener(DataGridEvent.ITEM_EDIT_END, onItemEditEnd);
...
// listener
private function onItemEditEnd(event:DataGridEvent):void {
// at this point itemEditorInstance is still available, so you can get entered value from it
// if itemEditorInstance is TextInput
var enteredValue:String = TextInput(cpDataGrid.itemEditorInstance).text;
}

Change cursor on datagrid row

I'm working on a flex project, and have a datagrid that I'd like the cursor to change when hovering over any row containing data.
I have double click enable on the datagrid and I'd like to indicate to the use that they can click the row they are hovering over.
This is what I've tried but it seems to just use the hand cursor on the datagrid its self and not the row data.
<mx:DataGrid x="9" y="47" width="330" height="244" useHandCursor="true" buttonMode="true" mouseChildren="true" horizontalScrollPolicy="{ScrollPolicy.AUTO}" styleName="resultgrid" dataProvider="{acLatest}" doubleClickEnabled="true" itemDoubleClick="doubleClickoverview()" id="overviewLatest_dg">
<mx:columns>
<mx:DataGridColumn headerText="Tag" id="overviewLatest_dg_animal_ptag" visible="true" dataField="animal_ptag" width="110" />
<mx:DataGridColumn headerText="Status" id="overviewLatest_dg_status_status" visible="true" dataField="status_status" width="110"/>
<mx:DataGridColumn headerText="Sex" id="overviewLatest_dg_animal_sex" visible="true" dataField="animal_sex" width="110"/>
</mx:columns>
</mx:DataGrid>
I would create an itemRenderer and add event listeners for the MouseEvent.ROLL_OVER and MouseEvent.ROLL_OUT events. In the event handlers you can change the cursor using the cursorManager. This also has the added benefit of allowing you to change the cursor based on some data or condition for the row the user is hovering their cursor over.
Here's an example on changing the cursor when mousing over a component. Hopefully this gets you started in the right direction.
Ended up using itemRollOver & itemRollOut on the datagrid.
Then just created a simple class that changes the cursor to a hand image.
DataGrid:
itemRollOver="Cursors.setHandCursor()" itemRollOut="CursorManager.removeAllCursors()"
Cursor Class:
package com {
import mx.managers.CursorManager;
import mx.managers.CursorManagerPriority;
public class Cursors extends CursorManager {
private static var handCursorList:Array = [];
public static function setHandCursor():void {
[Embed(source="../images/hand.png")]
var handCursorClass:Class;
handCursorList.push(setCursor(handCursorClass, CursorManagerPriority.MEDIUM));
}
}
}

Flex Advanced Datagrid - access value of itemrenderer of one column from other column

I have a AdvancedDatagrid with two columns lets say.
First column has item renderer as DropdownList.
Now, on change of DropdownList, I want to update label in second column, how would I do that?
You can access flex objects with their IDs just like here. Hope this helps
<mx:DataGridColumn headerText="FirstColumn" id="yourFirstColumnId" dataField="FirstColumnDataProvider" change="functionName">
<fx:Script>
<![CDATA[
public function functionName():void
{
yourSecondColumnId.headerText= "".
}
]]>
</fx:Script>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="SecondColumn" id="yourSecondColumnid" >

HTTPService Issue returning GeoCode results to DataGrid

I am creating a Flex3 app to return some results from the Google Geocoding API.
I am using the HTTPService Events sample from TourDeFlex as a reference guide to mimic.
For now, I have hardcoded the response from Google to use this XML response:
maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false
Network Monitor suggests that I am getting a valid response from the XML, but I imagine I have not referenced it correctly for populating my DataGrid?
I have screencasted the issue here.
Here is a stripped down version of my code:
private function resultHandler(event:ResultEvent):void
{
results = event.result.GeocodeResponse.result;
}
private function faultHandler(event:FaultEvent):void
{
Alert.show(event.fault.faultDetail, "Error");
}
]]>
</mx:Script>
<mx:HTTPService id="srv"
url="http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false"
result="resultHandler(event)"
fault="faultHandler(event)"/>
<mx:TitleWindow title="Find" showCloseButton="true" close="closeMe();"
styleName="formPanel" horizontalScrollPolicy="off" verticalScrollPolicy="off"
width="400" height="200">
<mx:DataGrid dataProvider="{results}" width="100%" height="100%">
<mx:columns>
<mx:DataGridColumn dataField="type" headerText="Address"/>
</mx:columns>
</mx:DataGrid>
<mx:Button label="Go" height="20" styleName="buttonGo" click="srv.send()"/>
</mx:TitleWindow>
Had a look at the xml. It could be that the first occurance of type is at a top level, but from then on type is an element of address_component.
Maybe try address_component.type as the datafield of the DataGridColumn? Or set the dataprovider to results.address_component?
Edit Update
Because its reading XML, maybe set resultFormat="e4x" inside the <HttpService ..> tag, and have an XMLListCollection awaiting the result:
<mx:XMLListCollection id="xc" source="{srv.lastResult.result}"/>
<mx:DataGrid id="dg" dataProvider="{xc}">
In debug mode, set a watch on XC to make sure its being populated

getting mx:CheckBox values from inside mx:Repeater

I have an an array of objects that I use as the datasource for my repeater.
<mx:Repeater id="categoryRepeater" dataProvider="{this.allCategories}">
<mx:HBox>
<mx:Spacer width="20"/>
<mx:CheckBox id="categoryCheckBox" label="{categoryRepeater.currentItem.question}"/>
</mx:HBox>
</mx:Repeater>
I would like to be able to tell which of the checkboxes in the list have been checked, but I'm not sure how to do it. I know I can add a function when it's clicked, but I don't know how to tell which checkbox called the function.
Use the currentIndex property.
I realize that this is a very old post, but I had run into the same issue and the currentIndex was not a sufficient answer for me. What I found to work better was to create a function on click:
<mx:Repeater id="rp" dataProvider="{dp}">
<s:CheckBox height="100%" width="100%" label="{String(rp.currentItem)}"
click="showAlert(event);"/>
</mx:Repeater>
and the showAlert function looks something like this:
private function showAlert(evt:MouseEvent):void {
var curBox:CheckBox = evt.currentTarget as CheckBox;
var str:String = curBox.content.toString();
if(curBox.selected)
Alert.show(str + " clicked");
}
This way you can deal with the event as a CheckBox inside of your ActionScript code and find values such as whether or not it has been selected etc.