0

我正在使用 Flex 4.5 SDK 开发一个移动程序,这是我的学校论文。我的程序中有一个无法修复的错误。

我有一个视图,我有 2 个状态。当我从状态更改时,我的程序不再监听 backKey 事件。我已经尝试过这个:

backKeyPressed.mystate = "backKeyPressed(event)"

但这无济于事。我做了一个小程序给你看:

<?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="Home"
    initialize="init()"
    backKeyPressed="view1_backKeyPressedHandler(event)">

<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        import mx.events.FlexEvent;

        [Bindable]
        private var m_list:ArrayCollection = new ArrayCollection();

        private function init():void
        {

        }

        protected function button1_clickHandler(event:MouseEvent):void
        {
            currentState = 'state2';

        }

        protected function button2_clickHandler(event:MouseEvent):void
        {
            currentState = 'state1';

        }

        protected function view1_backKeyPressedHandler(event:FlexEvent):void
        {
            event.preventDefault();

        }

    ]]>
</fx:Script>
<fx:Declarations>
    <s:State name="state1"/>
    <s:State name="state2"/>
</fx:Declarations>
<s:Group id="stateOneGroup" includeIn="state1">
    <s:Button x="30" y="112" label="To State 2"
              click="button1_clickHandler(event)"/>
    <s:Label x="72" y="216" text="State1"/>
</s:Group>

<s:Group id="stateTwoGroup" includeIn="state2">
    <s:Button x="267" y="112" label="To State 1"
              click="button2_clickHandler(event)"/>
    <s:Label x="303" y="216" text="State2"/>
</s:Group>

 </s:View>

如果它是一个错误,我也在adobe上搜索过,但我似乎没有找到它。

我希望有一个人可以帮助我。

亲切的问候,

蒂博海伦

4

1 回答 1

1

我今天有同样的问题。最后我明白了。在我的问题中,如果是第一个视图,则 backkeypressed 不起作用,但对于其他视图,backkeypressed 效果很好。

希望这可以帮助

于 2011-07-08T00:57:38.713 回答