Adobe Dreamweaver Forums



Last 10 THreads :         Re: Photoshop won't launch (Last Post : Ann_Shelbourne@adobeforums.com - Replies : 0 - Views : 1 )           »          Eventlistener for exiting frame (Last Post : Andrei1 - Replies : 1 - Views : 2 )           »          CS4 Motion Editor issues (Last Post : jdehaan - Replies : 3 - Views : 9 )           »          Flash file won't display (Last Post : Murray *ACE* - Replies : 18 - Views : 19 )           »          How do I centre Tables ? (Last Post : Murray *ACE* - Replies : 3 - Views : 4 )           »          3 overlapping background images on same page (Last Post : Murray *ACE* - Replies : 9 - Views : 10 )           »          Can I make a 4 state CSS Sprite nav bar. (Last Post : Murray *ACE* - Replies : 7 - Views : 8 )           »          Re: Photoshop CS3 Keeps on Crashing at Random - Help! (Last Post : Ann_Shelbourne@adobeforums.com - Replies : 0 - Views : 1 )           »          bad luck (Last Post : Andrei1 - Replies : 1 - Views : 2 )           »          ActivMail (cf_mail) and Bare LF problem (Last Post : Fetch - Replies : 1 - Views : 2 )           »         


User Info Statistics
Go Back   Adobe Dreamweaver Forums > Macromedia Software > Flex
 
Tags:



Reply
  #1 (permalink)  
Old 11-04-2008, 09:02 AM
RBKB
 
Posts: n/a
Diggs:
Default Combo box changes selected Item when dp refreshes

Hi,

I am using a combo box and its dataprovider is an arrayCollection (dp1.arr1,
dp1 is a actionscript class and arr1 is a global arraycollection for class).
The data is refreshed every minute. Hence, in the dp1 class, refreshData()
method gets called every minute and populates a new arraycollection arr2 with
the data everytime. And then lastly arr1 points to arr2. (ie. in code I write
arr1=arr2). This works fine.

But the problem is say if I had selected "value 3" in combo box. Now when
data refreshes and arr1=arr2, the combobox shows "value 1" i.e the 1st value in
the array.

What I want is the data in the combo box should be refreshed every min. and
also the selected value should not change. The data is bound to change
everytime. i.e some values might be deleted and some new values might be added.

Can somebody please provide me with an example for this or provide a solution
to my above problem so that the seleceted value in combo box remains same?






Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-04-2008, 09:02 AM
Greg Lafrance
 
Posts: n/a
Diggs:
Default Re: Combo box changes selected Item when dp refreshes

This code should help. As soon as the app launches, select value3. If the new
array has gthe previously selected item, it will still be selected, otherwise
it will of course revert to the first item.

----- components/dp1.as -----
package components
{
import flash.events.TimerEvent;
import flash.utils.Timer;

import mx.collections.ArrayCollection;
import mx.controls.Alert;

public class dp1{
[Bindable] public var arr1:ArrayCollection = new ArrayCollection([
"value1", "value2", "value3"
]);
public var arr2:ArrayCollection = new ArrayCollection([
"value1", "value2", "value3", "value4", "value5", "value6"
]);
public var arr3:ArrayCollection = new ArrayCollection([
"value1", "value2"
]);
private var timer:Timer = new Timer(10000, 0);
private var cnt:uint = 1;

public function dp1(){
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
}

public function timerHandler(event:TimerEvent):void{
if(cnt++ % 3 == 0){
mx.controls.Alert.show("Switched to arr3, should NOT see value3.");
arr1 = arr3;
}else if(cnt++ % 2 == 0){
mx.controls.Alert.show("Switched to arr2, SHOULD see value3.");
arr1 = arr2;
}
arr1.refresh();
}
}
}
----------------------------------------------------------
----- ComboBoxController.mxml -----
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
import components.dp1;
import mx.events.PropertyChangeEvent;
import mx.binding.utils.ChangeWatcher;

[Bindable] public var dp1:components.dp1 = new components.dp1();
[Bindable] private var cbxSelected:Object;
private var activityWatcher:ChangeWatcher;

private function init():void{
if(ChangeWatcher.canWatch(cbx, "dataProvider")){
activityWatcher = ChangeWatcher.watch( cbx, "dataProvider",
cbxDataProviderChangeHandler);
}
}

private function cbxDataProviderChangeHandler( event:CollectionEvent
):void{
var newDP:ArrayCollection = event.currentTarget.dataProvider as
ArrayCollection;
if(newDP.contains(cbxSelected)){
cbx.selectedIndex =
cbx.dataProvider.getItemIndex(cbxSelected.toString ());
}
}
]]>
</mx:Script>
<mx:ComboBox id="cbx" dataProvider="{dp1.arr1}"
change="cbxSelected=cbx.selectedItem"/>
</mx:Application>

Reply With Quote
  #3 (permalink)  
Old 11-04-2008, 09:02 AM
Mitek17
 
Posts: n/a
Diggs:
Default Re: Combo box changes selected Item when dp refreshes

I've already replied in flexcoders, please see my solution to this ComboBox problem:

http://mitek.id.au/blog/2008/10/28/c...ess-continues/

Cheers,
Dmitri.
Reply With Quote


Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 01:28 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk