0 Replies Latest reply on Apr 11, 2013 4:23 AM by soul-mapp

    Toggle Switch losing its “on” state, once i change view in stack

    soul-mapp

      I making a app with flash builder 4.6. and i have settings page where you can turn on/off background music and few other options. but once i go to a different view of the stack, when i come back to the setting view the toggle switch have forgotten its last state, ive tried using destructionPolicy="never" but it dont help.. does anyone have any ideas?? here is my code so far..

       

      Here is what ive got so far..

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009"

                                  xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.BgAppHomeView" applicationDPI="320">

          <fx:Declarations>

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

          </fx:Declarations>

      </s:ViewNavigatorApplication>

       

       

       

      Apps First View.....

      <?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="HomeView"

              destructionPolicy="never">

          <fx:Declarations>

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

          </fx:Declarations>

         

          <s:actionContent>   

                  <s:Button label="Next" click="navigator.pushView(views.BgAppSettingView)"/>   

          </s:actionContent>

      </s:View>

       

       

      Apps Settings View....

      <?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="App Settings"

              destructionPolicy="never">

         

          <fx:Script>

              <![CDATA[

                  import flash.media.*;

                  import flash.media.SoundChannel;

                  import flash.media.SoundTransform;

                 

                  [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;

                 

                  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;

                          lbl.text=event.target.id + " changed, selected = " + event.target.selected;

                          trace ("Started Background Music");

                      }   

                      else if (toggleSwitch.selected == false)

                      {                   

                          sndChannel.stop();

                          lbl.text=event.target.id + " changed, selected = " + event.target.selected;

                          trace ("Stop Background Music");

                      }           

                     

                  }

              ]]>       

          </fx:Script>

         

          <fx:Declarations>

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

          </fx:Declarations>

       

          <s:states>

              <s:State name="normal" />

              <s:State name="disabled" />

          </s:states>

         

          <s:actionContent>

              <s:HGroup>

                  <s:Button icon="assets/next.png" click="navigator.pushView(views.BgAppHomeView)"/>

              </s:HGroup>

          </s:actionContent>

             

       

          <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.normal="300" y.normal="185" color="#FFFFFF"/>

          <s:Label id="lbl" x="400" y="185"

                   x.normal="20" y.normal="247"/>

      </s:View>

       

      Message was edited by: soul-mapp