Flex 4 S:List how to add text items with code

Posted on 2011-02-26
Last Modified: 2012-05-11
<s:List id="playerList" x="675" y="20" width="44" height="206" ></s:List>

I want to add List of the Players in my game in code.

something like I
protected function button1_clickHandler(event:MouseEvent):void
          var s: String = "Player 1"
Question by:yahoolane
  • 2
LVL 17

Expert Comment

ID: 34989971
Try this:
protected function button1_clickHandler(event:MouseEvent):void
     var s: String = "Player 1";

Open in new window

Warm Regards
Deepanjan Das

Author Comment

ID: 34990075

No addItem for S:List

I am using Flex 4


LVL 17

Accepted Solution

deepanjandas earned 180 total points
ID: 34990134
Sorry Lane,
I just missed out. Try this:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="" 
			   xmlns:mx="library://" minWidth="955" minHeight="600">
		<!-- Place non-visual elements (e.g., services, value objects) here -->
			import mx.collections.ArrayCollection;
			private var playersList:ArrayCollection = new ArrayCollection();
			private function button1_clickHandler(event:MouseEvent):void
				var s: String = "Player 1";
		<s:Button click="button1_clickHandler(event);" label="ADD"/>
		<s:List id="playerList" x="100" y="100" dataProvider="{playersList}" width="100" height="206" ></s:List>

Open in new window

Warm Regards
Deepanjan Das

Featured Post

Promote certifications in your email signature

Has your company recently won an award or achieved a certification? They'll no doubt want to show it off. Email signature images used to promote certifications & awards can instantly establish credibility with a recipient and provide you with numerous benefits.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
There are many Password Managers (PM) out there to choose from. PM's can help with your password habits and routines, but they should not be a crutch you rely on too heavily. I also have an article for company/enterprise PM's.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now