一旦我在堆栈中更改视图,Toggle Switch就会失去“on”状态

时间:2013-04-09 11:19:15

标签: flash-builder flexbuilder

我使用Flash Builder 4.6创建应用程序。我有设置页面,您可以打开/关闭背景音乐和其他一些选项。但是一旦我进入堆叠的不同视图,当我回到设置视图时,切换开关已经忘记了它的最后状态, 香港专业教育学院尝试使用destructionPolicy =“从不”但它没有帮助..有没有人有任何想法? 这是我目前的代码..

<fx:Script>
    <![CDATA[
        import flash.media.*;
        import flash.media.SoundChannel;
        import flash.media.SoundTransform;

        import spark.components.mediaClasses.VolumeBar; 

        [Embed(source="assets/bgtrack.mp3")]

        [Bindable]
        private var sndCls:Class;
        private var snd:Sound = new sndCls() as Sound; 
        private var sndChannel:SoundChannel;
        private var _soundTransform:SoundTransform = new SoundTransform();
        private var radioplay:Boolean = false;

        private function init():void
        {               
            volBar.snapInterval =.1;
            volBar.value = .1;
            volBar.addEventListener(Event.CHANGE, ChangeVolume);    
        }     

        private function ChangeVolume(evt:Event):void
        {
            _soundTransform.volume = evt.target.value;
            sndChannel.soundTransform = _soundTransform;
            trace(evt.target.value);
        } 

        protected function toggleSwitch_changeHandler(event:Event):void
        {
            // TODO Auto-generated method stub
            if (toggleSwitch.selected == true)
            {   
                sndChannel=snd.play(0, 9999);
                _soundTransform.volume = .1;
                sndChannel.soundTransform = _soundTransform;            
            }   
            else if (toggleSwitch.selected == false)
            {                   
                sndChannel.stop();
                trace ("Stop Background Music");
            }           

        }

    ]]>     
</fx:Script>

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here --> 
</fx:Declarations>

<s:Image id="playsd" x="32" y="612" click="AudioOn(event)" source="assets/playbtn.png"/>
<s:HSlider id="volBar" minimum="0" maximum="1" x="266" y="661" width="320"/>    
<s:ToggleSwitch x="53" y="168" id="toggleSwitch" change="toggleSwitch_changeHandler(event)"/>
<s:Label id="status" x="53" y="268" text="{toggleSwitch.selected ? 'ON' : 'OFF'}"
         x="300" y="185" color="#FFFFFF"/>

感谢

0 个答案:

没有答案