开发者

Create an array from input field values with Flex 4.5

开发者 https://www.devze.com 2023-03-28 10:55 出处:网络
I have not been able to find any documentatio开发者_如何学Gon and searches return useless docs not involving what I want to do.

I have not been able to find any documentatio开发者_如何学Gon and searches return useless docs not involving what I want to do.

I want to take the text entered by the user, and when they click Add Record it adds the text to the array. The list box at the bottom displays each item in the array in the order it was entered.

I am just a beginner with a basic understanding of how the code is written, but I have no idea which things to use in order to take the text, make it into a string, add it to the array, and display the array in the list.

Create an array from input field values with Flex 4.5


The trick here is to just use the buttons click event to add an item to the ArrayCollection you use to provide the data to your list. Here's the sample I just came up with which does what I think you are asking:

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark"
    title="HomeView">

<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        [Bindable]
        private var _records:ArrayCollection = new ArrayCollection();

        protected function addRecord(event:MouseEvent):void
        {
            if(textInput.text != "") {
                _records.addItem(textInput.text);
            }
        }
    ]]>
</fx:Script>

<s:TextInput id="textInput" left="10" right="10" top="5" prompt="Enter Text" />
<s:Button top="64" label="Add Record" horizontalCenter="0" click="addRecord(event)" />
<s:List left="10" right="10" top="132" bottom="5" dataProvider="{_records}" />
</s:View>
0

精彩评论

暂无评论...
验证码 换一张
取 消