0

这个可能很简单,但我在网上找不到答案。这是我所拥有的:

<fx:Script>
        <![CDATA[
            protected function DestIsAirport(event:MouseEvent):void {
                navigator.pushView(AirportSelector);
            }
            protected function DestIsAddress(event:MouseEvent):void {
                navigator.pushView(DestinationInfoView);
            }
        ]]>
</fx:Script>

然后我在它下面有一个弹出容器,它看起来像这样:

<fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
        <fx:Component className="DestAlert">
            <s:SkinnablePopUpContainer x="50" y="200">
                <s:TitleWindow title="Destination">
                    <s:VGroup horizontalAlign="center" verticalAlign="middle" paddingTop="8" paddingBottom="8" paddingLeft="8" paddingRight="8" gap="5" width="100%">
                        <s:Label text="Is your destination an airport?"/>
                    </s:VGroup>
                    <s:HGroup horizontalAlign="center" verticalAlign="middle" paddingTop="40" paddingBottom="8" gap="5" width="100%">
                        <s:Button label="Yes" bottom="10" left="10" width="100" fontSize="16" click="DestIsAirport(event)"/>
                        <s:Button label="No" bottom="10" right="10" width="100" fontSize="16" click="DestIsAddress(event)"/>
                    </s:HGroup>
                </s:TitleWindow>
            </s:SkinnablePopUpContainer>
        </fx:Component>
    </fx:Declarations>

我希望这两个按钮从 AS3 脚本运行不同的功能。这会产生错误:1180:调用可能未定义的方法 DestIsAddress。1180:调用可能未定义的方法 DestIsAirport。

如何让这些按钮运行这两个功能?

整个源文件:

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark" title="Enter Pick Up Address">

    <fx:Script>
        <![CDATA[
            protected function button1_clickHandler(event:MouseEvent):void
            {
                navigator.popView();
            }
            protected function DestIsAirport(event:MouseEvent):void {
                navigator.pushView(AirportSelector);
            }
            protected function DestIsAddress(event:MouseEvent):void {
                navigator.pushView(DestinationInfoView);
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
        <fx:Component className="DestAlert">
            <s:SkinnablePopUpContainer x="50" y="200">
                <s:TitleWindow title="Destination">
                    <s:VGroup horizontalAlign="center" verticalAlign="middle" paddingTop="8" paddingBottom="8" paddingLeft="8" paddingRight="8" gap="5" width="100%">
                        <s:Label text="Is your destination an airport?"/>
                    </s:VGroup>
                    <s:HGroup horizontalAlign="center" verticalAlign="middle" paddingTop="40" paddingBottom="8" gap="5" width="100%">
                        <s:Button label="Yes" bottom="10" left="10" width="100" fontSize="16" click="close()"/>
                        <s:Button label="No" bottom="10" right="10" width="100" fontSize="16" click="close()"/>
                    </s:HGroup>
                </s:TitleWindow>
            </s:SkinnablePopUpContainer>
        </fx:Component>
    </fx:Declarations>
    <s:actionContent>
        <s:Button label="Back" click="button1_clickHandler(event)"/>
    </s:actionContent>
    <s:TextInput top="6" horizontalCenter="-1" prompt="Address Line 1"/>
    <s:TextInput top="47" horizontalCenter="-1" prompt="Address Line 2"/>
    <s:RadioButton top="90" label="IL - Illinois" horizontalCenter="-94"/>
    <s:RadioButton top="90" label="WI - Wisconsin" horizontalCenter="72"/>
    <s:SpinnerListContainer bottom="60" width="320" height="211" horizontalCenter="0">
        <s:SpinnerList width="317" height="100%" labelField="data" selectedIndex="0">
            <s:ArrayList>
                <fx:Object data=""></fx:Object>
                <fx:Object data="Abbott Park"></fx:Object>
                <fx:Object data="Addison"></fx:Object>
                <fx:Object data="Algonquin"></fx:Object>
                <fx:Object data="Alsip"></fx:Object>

    </s:ArrayList>
        </s:SpinnerList>
    </s:SpinnerListContainer>
    <s:Button bottom="10" width="302" label="Next" click="(new DestAlert()).open(this, false)"
              fontSize="24" horizontalCenter="0"/>
</s:View>
4

2 回答 2

1

声明部分仅适用于用户不会看到的内容。你需要做几件事。

  1. 获取声明部分中的组件并将其移动到它自己的文件中。
  2. 通过弹出管理器显示组件的实例。

此外,重要的是要注意组件和父级将处于完全不同的范围内。但是,在创建弹出组件的新实例后,您可以使用对它的引用来添加侦听器。然后组件可以调度此类可以侦听的事件,然后调用函数。

这变得更加复杂,因为 popupmanager 是一个静态类,与您在此处添加的代码无关。让我知道这是否需要更多解释,因为我几乎觉得照片是有序的。

于 2012-06-14T21:15:10.913 回答
0

为什么不创建一个单独的动作脚本/mxml 文件?那很容易解决这个问题。

于 2012-06-14T19:03:11.387 回答