You can dispatch event from your custom MXML component...

I suggest, having setters/getters functions in your custom component.
Whenever a property is set,
dispatch appropriate event.

Read docs more about dispatching event.

-abdul



On 1/25/07, paperbyolga <[EMAIL PROTECTED]> wrote:

  Hi, i need help with a change event listener. I want to simply fire
off a call to a webservice when a variable changes.

I have a combobox that fires a function that sets a variable that
gets passed to a component. if the variable changes in the
component, i want to fire a webservice to get new data... perhaps
there is a simple way to do this... so i'm open, thought an event
listener would do the trick, but.... i've looked at a few things and
frankly... i'm lost. New to flex, so getting my head around client
server versus web programming is a challenge. any examples, help or
direction would be great. thanks in advance. code is below.

Shane

***** main comp ****

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"; width="100%"
height="100%" backgroundColor="#ffffff"
horizontalScrollPolicy="off" verticalScrollPolicy="off"
initialize="locws.getStates.send();" xmlns:st="stat.*">

<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.utils.ArrayUtil;
import mx.events.TreeEvent;

[Bindable]
private var thisLocationType:int = 0;
[Bindable]
private var thisLocationCode:String = '00';
[Bindable]
private var thisLocLabel:String = '';



private function changeState():void {

if (statsHome.visible == false) {
statsHome.visible = true;
}

if (locStates.selectedItem.LOC_CODE
== '00') {
currentState='';
} else {

currentState='locstateselected';
vCountyRadio.selected=false;
vMetroRadio.selected=false;
}

lbHist.text = 'History: ';
thisLocLabel =
locStates.selectedItem.LOC_NAME;
csState.label = '> ' +
locStates.selectedItem.LOC_NAME;
thisLocationCode =
locStates.selectedItem.LOC_CODE;
thisLocationType = 0;
csSubLoc.label = '';
csZipcode.label = '';

}

private function clickLocType
(loctype:int):void {

currentState='locsublocselected';
thisLocationType = loctype;
thisLocationCode = '';

if (loctype == 1) {
locws.getCounties.send();
subLocations.dataProvider =
theCountiesList;
} else if (loctype == 2) {
locws.getCities.send();
subLocations.dataProvider =
theCitiesList;
}

}

private function changeSubLocation():void {

if (thisLocationType == 1) {
thisLocationCode =
locStates.selectedItem.LOC_CODE + subLocations.selectedItem.LOC_CODE;
} else if (thisLocationType == 2) {
thisLocationCode =
subLocations.selectedItem.LOC_CODE;
}

if (thisLocationType != 0) {
locws.getZipcodes.send();
thisLocLabel =
subLocations.selectedItem.LOC_NAME;
csSubLoc.label = '> ' +
subLocations.selectedItem.LOC_NAME;
currentState='zipstate';
csZipcode.label = '';
}

}

private function setLocation():void {
thisLocationType = 4;
thisLocationCode =
zipcodes.selectedItem.LOC_CODE;
thisLocLabel =
zipcodes.selectedItem.LOC_NAME;
csZipcode.label = '> ' +
zipcodes.selectedItem.FULL_NAME;
}

private function error():void
{
Alert.show("Error getting data... refresh
the browser to try again.", "Error");
}

]]>
</mx:Script>

<mx:WebService id="locws"
wsdl="{parentApplication.webServiceRootUrl}"
useProxy="false"
showBusyCursor="true"
fault="error()">

<mx:operation name="getStates" />

<mx:operation name="getCounties">
<mx:request>
<statecode>{locStates.selectedItem.LOC_CODE}
</statecode>
</mx:request>
</mx:operation>

<mx:operation name="getCities">
<mx:request>
<statecode>{locStates.selectedItem.LOC_CODE}
</statecode>
</mx:request>
</mx:operation>

<mx:operation name="getZipcodes">
<mx:request>
<loctype>{thisLocationType}</loctype>
<loccode>{thisLocationCode}</loccode>
</mx:request>
</mx:operation>

</mx:WebService>

<mx:ArrayCollection id="theStatesList"
source="{ArrayUtil.toArray(locws.getStates.lastResult)}" />
<mx:ArrayCollection id="theCountiesList"
source="{ArrayUtil.toArray(locws.getCounties.lastResult)}" />
<mx:ArrayCollection id="theCitiesList"
source="{ArrayUtil.toArray(locws.getCities.lastResult)}" />
<mx:ArrayCollection id="theZipcodeList"
source="{ArrayUtil.toArray(locws.getZipcodes.lastResult)}" />

<mx:states>

<mx:State name="locstateselected">
<mx:AddChild relativeTo="{hblocstates}"
position="lastChild">
<mx:VBox>
<mx:RadioButton label="View
Counties" fontWeight="bold" id="vCountyRadio" click="clickLocType
(1);"/>
<mx:RadioButton label="View
Cities" fontWeight="bold" id="vMetroRadio" click="clickLocType(2);"/>
</mx:VBox>
</mx:AddChild>
<mx:AddChild relativeTo="{statsHome}"
position="before">
<mx:VBox id="breadcrumb"
width="100%" height="22">
<mx:HBox width="100%"
verticalAlign="middle">
<mx:Label
id="lbHist" fontWeight="bold" />
<mx:LinkButton
id="csState" toolTip="Click to return to this view"
click="changeState()" />
<mx:LinkButton
id="csSubLoc" toolTip="Click to return to this view"
click="changeSubLocation()" />
<mx:LinkButton
id="csZipcode" enabled="false" />
</mx:HBox>
</mx:VBox>
</mx:AddChild>
</mx:State>

<mx:State name="locsublocselected"
basedOn="locstateselected">
<mx:AddChild relativeTo="{hblocstates}"
position="lastChild">
<mx:ComboBox id="subLocations"
color="#000000" labelField="LOC_NAME" prompt="Select Location"
change="changeSubLocation()" />
</mx:AddChild>
</mx:State>

<mx:State name="zipstate"
basedOn="locsublocselected">
<mx:AddChild relativeTo="{hblocstates}"
position="lastChild">
<mx:ComboBox id="zipcodes"
color="#000000" labelField="FULL_NAME"
dataProvider="{theZipcodeList}" prompt="Select Zip Code"
change="setLocation()" />
</mx:AddChild>
</mx:State>

</mx:states>


<mx:ApplicationControlBar id="mainControl" width="100%"
height="50" verticalAlign="top"
fillColors="[#6699CC, #6699CC]" fillAlphas="[1.0,
1.0]"
color="#FFFFFF">
<mx:HBox id="hblocstates" width="100%">
<mx:ComboBox id="locStates" color="#000000"
dataProvider="{theStatesList}" labelField="LOC_NAME" width="200"
change="changeState()" prompt="Select State" />
</mx:HBox>
<!-- <mx:HBox width="100%" horizontalAlign="right"
height="50">
<mx:Label text="Search:"/>
<mx:TextInput id="searchtext" width="100"/>
<mx:Button label="Go" id="searchbutton"/>
</mx:HBox> -->
</mx:ApplicationControlBar>

<mx:HBox id="statsHome" visible="false" width="100%"
height="100%">
<mx:Panel id="menupanel" width="25%"
height="100%"
title="The Details"
fontSize="12"
borderColor="#6699CC"
borderAlpha="1"
color="#FFFFFF">
<mx:VBox>
<mx:LinkButton label="Link Button 1"
color="#000000" width="100%" />
<mx:LinkButton label="Link Button 2"
color="#000000" width="100%" />
<mx:LinkButton label="Link Button 3"
color="#000000" width="100%" />
<mx:LinkButton label="Link Button 4"
color="#000000" width="100%" />
</mx:VBox>
</mx:Panel>
<mx:VBox width="75%" height="100%"
id="statviewervbox">
<stat:home locationCode="{thisLocationCode}"
locationType="{thisLocationType}" locLabel="{thisLocLabel}" />
</mx:VBox>
</mx:HBox>

</mx:VBox>

***** addtional comp so far *****

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"; width="100%"
height="100%">
<mx:Script>
<![CDATA[
[Bindable]
public var locationType:int = 0;
[Bindable]
public var locationCode:String = '';
[Bindable]
public var locLabel:String = '';
]]>
</mx:Script>

<mx:Label text="{locLabel}" />
<mx:Label text="{locationType}" />
<mx:Label text="{locationCode}" />

</mx:VBox>

Reply via email to