尝试包含'* .as'而不是<fx:script> </fx:script>

时间:2011-06-15 19:47:38

标签: actionscript-3 flex4 mxml flash-builder

我有一个手风琴组件嵌套在一个标签导航器中。每个手风琴窗格都有一个表格。表单有两个网格,可以在彼此和几个按钮之间来回传输数据以帮助他们。我有控制表单的动作脚本。 *感谢The_asMan帮我解决这个问题。

在“表单”包中,FormFunctions.as:

import mx.collections.ArrayCollection;

[Bindable]
public var originalData:ArrayCollection;

[Bindable]
public var changingData:ArrayCollection;

public function init( ):void
{
    this.changingData = new ArrayCollection( );
    this.originalData = new ArrayCollection( );
    for( var i:int = 0;i<100;i++)
    {
        var obj:Object = new Object( );
        obj.label = 'slot '+ i;
        obj.value = 's'+i;
        originalData.addItem( obj );
    }
}

public function addItem():void
{
    this.changingData.addItem(myStaticDataGrid.selectedItem );
    this.originalData.removeItemAt(myStaticDataGrid.selectedIndex);
}

public function clearList():void
{
    this.changingData.removeAll();
    init();
}
public function removeItem():void
{
    this.changingData.removeItemAt(bdgFormData.selectedIndex);
    this.originalData.addItem(bdgFormData.selectedItem );
}

我的标签nav / accordian看起来像这样:

<mx:TabNavigator id="myTabNav">
    <s:NavigatorContent id="myFirstTab">
        <mx:Accordion id="myFirstAccordNav">
            <s:NavigatorContent id="myFirstAccordPane">
                <forms:DualGridStyle id="myFirstForm"/>
            </s:NavigatorContent>
            <s:NavigatorContent id="mySecondAccordPane">
                <forms:DualGridStyle id="mySecondForm"/>
            </s:NavigatorContent>
         </mx:Accordion>
      </s:NavigatorContent>
      <s:NavigatorContent id="mySecondTab">
         <mx:Accordion id="mySecondAccordNav">
            <s:NavigatorContent id="myThirdAccordPane">
                <forms:DualGridStyle id="myThirdForm"/>
            </s:NavigatorContent>
            <s:NavigatorContent id="myFourthAccordPane">
                <forms:DualGridStyle id="myFouthForm"/>
            </s:NavigatorContent>
         </mx:Accordion>
      </s:NavigatorContent>
</mx:TabNavigator>

标签是我的自定义表单组件。这是代码:

<s:Form xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx" width="800" height="400">
<s:layout>
    <s:BasicLayout/>
</s:layout>
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label id="lblFilter" x="40" y="24" text="Filter:"/>
<s:TextInput id="txtFilter" x="83" y="20" width="145"/>

<s:DataGrid id="myStaticDataGrid" left="40" top="60" width="188" 
            creationComplete="init()" dataProvider="{originalData}"/>
<s:DataGrid id="bdgFormData" top="60" width="284" dataProvider="{changingData}"
            horizontalCenter="110"/>
<s:Button id="btnAdd" label="Add" top="90" left="262" 
          click="addItem()"/>
<s:Button id="btnRemove" label="Remove" top="90" horizontalCenter="310" 
          click="removeItem()" />
<s:Button id="btnClear" label="Clear" top="120" horizontalCenter="310" 
          click="clearList()"/>

</s:Form>

我的问题可能是一个简单的答案。如何让自定义表单从FormFunctions.as中识别AS函数?

1 个答案:

答案 0 :(得分:1)

将您的点击事件设置为:

click="addItem(event)"

和addItem函数:

private function addItem(e:MouseEvent):void
{