4 Replies Latest reply on May 12, 2010 5:11 AM by David_F57

    SWF Loader and MovieClip problems

    djh88ukwb Level 1

      Hello all.

       

      I am using the following code to import a swf file that has a number or frames.  When i hit next or previous it moves either to the next or previous frame.


      The code is as follows

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" applicationComplete="load()">   
          <mx:Script>
              <![CDATA[
                  private var flashMovie:MovieClip;
                 
                  private function initMovie():void{
                      flashMovie = loader.content as MovieClip;
                  }       
                  private function load():void{
                      flashMovie.stop()
                  }
              ]]>
          </mx:Script>
          <mx:SWFLoader id="loader" source="flash.swf" complete="initMovie()"/>
          <mx:Button label="Next" click="flashMovie.nextFrame()"/>
          <mx:Button label="Previous" click="flashMovie.prevFrame()"/>
      </mx:Application>

       

      This works fine, everything is as i want, apart from i want what ever SWF frame is being displayed, to be displayed on all web browsers that have the page open.

       

      I imagine i would be able to use an XML file, and pull the frame being displayed from that and have it check the XML file every couple of seconds ?

       

      Although saying that im not 100% sure on how to achieve this.

       

      Can anyone offer some help please?

        • 1. Re: SWF Loader and MovieClip problems
          djh88ukwb Level 1

          Ok,  So i have been working on this concerpt a little more.

           

          I have created a HTTPS service,

              <mx:HTTPService id="getImage" result="handleImage(event)" url="change.xml" method="POST">
                  <mx:request xmlns="">
                      <dataDumping>
                          {dataDump}
                      </dataDumping>
                  </mx:request>
              </mx:HTTPService>

           

          This pulling data from the XML file where i plan to store the frame that needs to be displayed on of the SWF file.

           

          I checked that the HTTP service was working by using the function

                      private function handleImage(event:ResultEvent):void
                      {
                          img1.source = event.result.imagelocation;
                      }

          And as i expected when i change the xml file, the image changes.

           

          However i created a variable

           

          private var i:String = "test";

          And planned to have the HTTP service change the value of this value. I assumed it would be the same code as what i previously used,so used the following code

                      private function handleImage(event:ResultEvent):void
                      {
                          var i = event.result.imagelocation;
                      }

           

          However using this, it dosent update the value of the variable being displayed in the text box,

          <mx:Text x="817" y="10" text="Total: {i}" width="157"/>

           

          Can anyone see where i am going wrong ?

          • 2. Re: SWF Loader and MovieClip problems
            David_F57 Level 5

            hi,

             

            first declare the var as bindable

             

            [Bindable] private var myText:String

             

             

                        private function handleImage(event:ResultEvent):void
                        {
                            myText = event.result.imagelocation;
                        }

             

             

            <mx:Text x="817" y="10" text="Total: {myText}" width="157"/>

             

             

            David.

            • 3. Re: SWF Loader and MovieClip problems
              djh88ukwb Level 1

              David thanks yet again ! You have helped me out yet again Thanks alot.

               

              Could i ask if its possible to create a function, that when you click it, it increments a value by 1 and then saves that value to the XML sheet.  So when it is clicked a second time, it takes the value from the XML sheet, adds 1 and saves it back to the XML sheet.

               

              I need to figure out how to do this, in order for the Next and Previous buttons to work on the following code.

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="load()">   
                  <mx:Script>
                      <![CDATA[
                          import mx.rpc.events.ResultEvent;
                         
                          [Bindable] public var dataDump:String = "datadump";
                          [Bindable] private var myText:String
                         
                          private var flashMovie:MovieClip;
                     
                          private function initMovie():void{
                              flashMovie = loader.content as MovieClip;
                          }           
                         
                          private function load():void{
                              flashMovie.gotoAndStop(myText)
                              getImage.send();
                              setTimeout(load,1000);
                          }
                         
                          private function handleImage(event:ResultEvent):void
                          {
                              myText = event.result.framelocation;
                          }
                      ]]>
                  </mx:Script>
                 
                  <mx:SWFLoader id="loader" source="flash.swf" complete="initMovie()" x="-9" y="-3"/>
                  <mx:Button label="Next" click="flashMovie.nextFrame()" x="78" y="405"/>
                  <mx:Button label="Previous" click="flashMovie.prevFrame()" x="0" y="405"/>
                  <mx:Button label="4" click="flashMovie.gotoAndPlay(7)" x="156" y="405"/>
                 
                  <mx:HTTPService id="getImage" result="handleImage(event)" url="change.xml" method="POST">
                      <mx:request xmlns="">
                          <dataDumping>
                              {dataDump}
                          </dataDumping>
                      </mx:request>
                  </mx:HTTPService>
                 
                  <mx:Text x="817" y="10" text="Total: {myText}" width="157"/>
                 
              </mx:Application>

               

              I need to be able to create a function that increments by one everytime the next button is clicked.  I know i will have to use a php script to alter the actual XML file, but im not sure on creating the flex side of things.

               

              If you could help i would be most thankful

              • 4. Re: SWF Loader and MovieClip problems
                David_F57 Level 5

                hi,

                 

                have a look at this code, it works differently to what you have described, but it may give you some idea's

                 

                http://gumbo.flashhub.net/imgmenu/ - source included

                 

                David