2012-10-29 54 views
1

我創建了一個列表組件,其中每個標籤的範圍從1到10都有不同的數字。當點擊一個數字時,我需要它來一個接一個地調出很多輸入文本框。列出組件來調出InputText框

這幾乎是一個多人遊戲,你選擇了多少玩家,然後你輸入每個名字..我很卡住這是可笑的..如果任何人有一個解決方案,或不同的想法,請幫助我,感謝你提前這麼多。

回答

1

有很多方法可以做到這一點。

Flash Professional中的方法

作者您的Flash Professional中的藝術板視圖。

包括列表控制,以及要顯示的文本框,如:

artboard

給屬性名到您的組件,如quantityList的名單以及答案文字輸入控件,例如answerBoxes自定義符號中的answer1

import flash.events.Event; 

quantityList.addItem({label:"1", data:1}); 
quantityList.addItem({label:"2", data:2}); 
quantityList.addItem({label:"3", data:3}); 
quantityList.addItem({label:"4", data:4}); 
quantityList.addItem({label:"5", data:5}); 
quantityList.addItem({label:"6", data:6}); 
quantityList.addItem({label:"7", data:7}); 
quantityList.addItem({label:"8", data:8}); 
quantityList.addItem({label:"9", data:9}); 
quantityList.addItem({label:"10", data:10}); 

quantityList.addEventListener(Event.CHANGE, changeHandler); 

function changeHandler(event:Event):void 
{ 
    var numberOfQuestions = event.target.selectedItem.data as int; 

    answerBoxes.answer1.visible = (numberOfQuestions > 0 ? true : false); 
    answerBoxes.answer2.visible = (numberOfQuestions > 1 ? true : false); 
    answerBoxes.answer3.visible = (numberOfQuestions > 2 ? true : false); 
    answerBoxes.answer4.visible = (numberOfQuestions > 3 ? true : false); 
    answerBoxes.answer5.visible = (numberOfQuestions > 4 ? true : false); 
    answerBoxes.answer6.visible = (numberOfQuestions > 5 ? true : false); 
    answerBoxes.answer7.visible = (numberOfQuestions > 6 ? true : false); 
    answerBoxes.answer8.visible = (numberOfQuestions > 7 ? true : false); 
    answerBoxes.answer9.visible = (numberOfQuestions > 8 ? true : false); 
    answerBoxes.answer10.visible = (numberOfQuestions > 9 ? true : false); 
} 

當您運行,你可以從列表中選擇項目:

linkage

在代碼中,你可以通過添加這時間軸控制你的答案視圖的可見性

running

Working SWF Example

Flash Pro CS5.5 FLA source code

的Flex - 一種編程方法列表中的數據提供

number-game

存儲量數值和變化迭代添加元素:

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx"> 
    <s:layout> 
     <s:HorizontalLayout /> 
    </s:layout> 

    <fx:Script> 
     <![CDATA[ 
      import mx.collections.ArrayList; 

      import spark.components.TextInput; 
      import spark.events.IndexChangeEvent; 

      protected function quantityList_changeHandler(event:IndexChangeEvent):void 
      { 
       textInputGroup.removeAllElements(); 

       for (var i:uint = 0; i < quantityList.selectedItem; i++) 
       { 
        textInputGroup.addElement(new TextInput()); 
       } 
      } 
     ]]> 
    </fx:Script> 

    <s:List id="quantityList" 
      change="quantityList_changeHandler(event)" 
      dataProvider="{new ArrayList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])}" /> 

    <s:VGroup id="textInputGroup" /> 


</s:Application> 

的Flex - 一個聲明appraoch

number-game

使用Flex狀態系統,你可以聲明佈局視圖則包括所需的狀態的分量。你也可以在動畫之間加入狀態轉換。

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx"> 
    <s:layout> 
     <s:HorizontalLayout /> 
    </s:layout> 

    <fx:Script> 
     <![CDATA[ 
      import mx.collections.ArrayList; 

      import spark.components.TextInput; 
      import spark.events.IndexChangeEvent; 

      protected function quantityList_changeHandler(event:IndexChangeEvent):void 
      { 
       currentState = "quantity" + quantityList.selectedItem.toString(); 
      } 
     ]]> 
    </fx:Script> 

    <s:states> 
     <s:State name="quantity1" /> 
     <s:State name="quantity2" /> 
     <s:State name="quantity3" /> 
     <s:State name="quantity4" /> 
     <s:State name="quantity5" /> 
     <s:State name="quantity6" /> 
     <s:State name="quantity7" /> 
     <s:State name="quantity8" /> 
     <s:State name="quantity9" /> 
     <s:State name="quantity10" /> 
    </s:states> 

    <s:List id="quantityList" 
      change="quantityList_changeHandler(event)" 
      dataProvider="{new ArrayList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])}" /> 

    <s:VGroup id="textInputGroup"> 
     <s:TextInput includeIn="quantity1,quantity2,quantity3,quantity4,quantity5,quantity6,quantity7,quantity8,quantity9,quantity10" /> 
     <s:TextInput includeIn="quantity2,quantity3,quantity4,quantity5,quantity6,quantity7,quantity8,quantity9,quantity10" /> 
     <s:TextInput includeIn="quantity3,quantity4,quantity5,quantity6,quantity7,quantity8,quantity9,quantity10" /> 
     <s:TextInput includeIn="quantity4,quantity5,quantity6,quantity7,quantity8,quantity9,quantity10" /> 
     <s:TextInput includeIn="quantity5,quantity6,quantity7,quantity8,quantity9,quantity10" /> 
     <s:TextInput includeIn="quantity6,quantity7,quantity8,quantity9,quantity10" /> 
     <s:TextInput includeIn="quantity7,quantity8,quantity9,quantity10" /> 
     <s:TextInput includeIn="quantity8,quantity9,quantity10" /> 
     <s:TextInput includeIn="quantity9,quantity10" /> 
     <s:TextInput includeIn="quantity10" /> 
    </s:VGroup> 

</s:Application> 
+0

男人,我很新的這一點,我不知道如何使用actionscript..Hell的東西我甚至說,可能聽起來很無知的,因爲我敢肯定它不是..謝謝您雖然幫助到目前爲止.. – johnscott1989

+0

哦,你想要一個Flash Pro [list control](http://help.adobe.com/en_US/as3/components/WS5b3ccc516d4fbf351e63e3d118a9c65b32-7fa6.html)的例子。對不起,基本上與從您的列表中偵聽「Event.CHANGE」的編程方法相同。我會盡快添加該示例。 –

+0

老兄非常感謝你,我會弄清楚如何讓我在這個網站上的聲望,所以我可以upvote你的答案..謝謝這麼多人.. – johnscott1989