School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

ActionScript Source Code


Welcome to Dream.In.Code
Become an Expert!

Join 340,162 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 4,028 people online right now. Registration is fast and FREE... Join Now!




UI Component - List + Data Grid

This is a small script which shows how to have the list box component and the data grid component working together.

Submitted By: reyco1
Actions:
Rating:
Views: 10,537

Language: ActionScript

Last Modified: March 27, 2005
Instructions: drag a list box component and a data grid component and instance name them "listBox" and "dataGrid" respectfully. Paste the following code in the first frame of the movie.

Snippet


  1. import mx.controls.List;
  2. import mx.controls.DataGrid;
  3. // type your components
  4. var listBox:List;
  5. var dataGrid:DataGrid;
  6. // create arrays containing objects with your data
  7. var fruits:Array = new Array({name:'apple', weight:2, price:150}, {name:'mango', weight:3, price:140}, {name:'grape', weight:5, price:120});
  8. var vegetables:Array = new Array({name:'brinjal', weight:2, price:150}, {name:'radish', weight:3, price:140}, {name:'potatoe', weight:5, price:120});
  9. var flowers:Array = new Array({name:'rose', weight:2, price:150}, {name:'lily', weight:3, price:140}, {name:'sun', weight:5, price:120});
  10. // array containing info for the list box
  11. var main:Array = new Array({label:'Fruits', data:fruits}, {label:'Vegetables', data:vegetables}, {label:'Flowers', data:flowers});
  12. // set data provider for the list box to main array
  13. listBox.dataProvider = main;
  14. // set up listener for the list box so that when changed, it will populate the datagrid with associated info
  15. var listener:Object = new Object();
  16. listener.change = function(pEvent:Object) {
  17.      var selectItem:Object = pEvent.target.selectedItem;
  18.      dataGrid.dataProvider = selectItem.data;
  19. };
  20. listBox.addEventListener('change', listener);
  21.  

Copy & Paste


Comments

There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month