3 Replies Latest reply on Sep 6, 2010 2:11 AM by Phuong Thanh

    how to change background images in <s:application>

    Phuong Thanh Level 1

      hello!

      i want to make a webside by flex4 as  this web http://www.templatemonster.com/flash-cms-templates/29930.html

      But i don't know how to make change background images by click and make sound when load page.

      Can u help me ,please. sorry i write E not well.

      Thanks so much

       

      BUI THI PHUONG THANH- FROM VIETNAM

        • 1. Re: how to change background images in <s:application>
          ShardulSingh Level 3

          Hi,

          please create a sink for your application inside that put your image.And apply that skin to your application on any click.

           

          Below is the code.

           

           

          Main Application

          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                         xmlns:s="library://ns.adobe.com/flex/spark"
                         xmlns:mx="library://ns.adobe.com/flex/halo" xmlns:mx1="library://ns.adobe.com/flex/mx">

              <fx:Script>
                  <![CDATA[
                     
                      protected function btn_click(evt:MouseEvent):void {
                          this.setStyle("skinClass", MySkinClass);
                      }
                  ]]>
              </fx:Script>
             
              <s:Button label="Change BackGroundImage" click="btn_click(event);"/>
             
          </s:Application>

           

           

           

           

          MySkinClass

          <?xml version="1.0" encoding="utf-8"?>
          <s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
                  xmlns:s="library://ns.adobe.com/flex/spark"
                  xmlns:mx="library://ns.adobe.com/flex/mx">
              <!-- host component -->
              <fx:Metadata>
                  [HostComponent("spark.components.supportClasses.SkinnableComponent")]
              </fx:Metadata>
              <s:states>
                  <s:State name="normal" />
                  <s:State name="disabled" />
              </s:states>

              <s:BitmapImage source="@Embed('image1.jpg')"  smooth="true" left="0" right="0"  top="0" bottom="0"  />

          </s:Skin>

           

           

           

           

           

           

           

           

          with Regards,

           

          Shardul Singh Bartwal

          • 2. Re: how to change background images in <s:application>
            ShardulSingh Level 3

            Hi and related to the sound use following:-

             

             

             

                      private var sound:Sound;
                        private var channel:SoundChannel;
                        protected function application1_preinitializeHandler(event:FlexEvent):void
                        {
                            sound    = new Sound(new URLRequest("audio1.mp3"));
                            channel = sound.play();
                        }

             


                        protected function application1_creationCompleteHandler(event:FlexEvent):void
                        {
                            channel.stop();
                        }

             

             

            call 'application1_preinitializeHandler()' on preinitialize of your application.Then it will start playing sound.

             

            The I have called  application1_creationCompleteHandler() on the  creationComplete which stop playing sound when my application's creation completes.You can call it in other way too.

             

             

             

             

             

             

             

             

             

             

            with Regards,

             

            Shardul Singh Bartwal

            • 3. Re: how to change background images in <s:application>
              Phuong Thanh Level 1

              ok! thanks. i have done the change background.But in the sound. i can't do it because in flashbuilder ,it understand flex event

              i maken in my flashbuilder 4. may be i make  wrong?? can u help me please

              <?xml version="1.0" encoding="utf-8"?>
              <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                             xmlns:s="library://ns.adobe.com/flex/spark"
                             xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
                 
                  <fx:Script>
                      <![CDATA[
                          import mx.events.FlexEvent;
                          private var sound:Sound;
                          private var channel:SoundChannel;
                          protected function application1_preinitializeHandler(event:FlexEvent):void
                          {
                              sound    = new Sound(new URLRequest("http://mp3.zing.vn/mp3/nghe-bai-hat/Hanh-Phuc-Bat-Tan-New-Version-V-Music-Band-Ho-Ngoc-Ha. IW6COEZ7.html"));
                              channel = sound.play();
                          }
                                                 
                         
                          protected function application1_creationCompleteHandler(event:FlexEvent):void
                          {
                              channel.stop();
                          }
                                     
                        
                      ]]>
                  </fx:Script>
                  <s:Button x="134" y="90" label="Button" click="application1_preinitializeHandler(event)"/>
                     
                 
              </s:Application>

              it don't run