10 Replies Latest reply on Sep 10, 2009 5:40 PM by jojothefunkyflex

    SWFLoader

    hitesh.rawat Level 1

      Hi EveryOne,

       

      I'll be repeating a question which has been asked many a time in this community. I have also gone through earlier posts created.....with same topic but was not able to resolve the issue i had.

       

      I want to know how to Pause and Stop a SWF file running on a SWFLoader component ????????

       

      Another one......do we have Time line in Flex too......??? and how can we implement....Seeking the SWF Clip in SWFloader??? can we do it without using MovieClip class?????

       

      Following is the code i'm trying however not working.................

       

       

       

              public function stop():void
              {
             
              if (loader.content is MovieClip)

       

      {

       

          var clip:MovieClip = loader.content as MovieClip;

       

             clip.stop();

       

      }
              }


       

      Thaks all.

        • 1. Re: SWFLoader
          injpix Level 3

          The following link has source code that will hopefully answer most of your questions.

           

          http://kamil.ucoz.com/blog/2009-05-27-3

           

          To answer your question about Flex having a timeline, the answer is yes, but, it only has a fixed number of two frames.  The first frame contains the Flex progress indicator.  The second frame is the application itself and the Flex framework.  Look into SystemManager for more information, if needed.

          • 2. Re: SWFLoader
            ShardulSingh Level 3

            Hi,

            It will be better for you if you will use Loader instead of the SwfLoader.I am giving you the solution with the Loader.I have never been tried with the swfLoader. Pls find the code here of your problem's solution.Let me know if you have any issue with this.

             

             

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

            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

            layout="absolute" creationComplete="OnCreationComplete()">

            <mx:Script>

            <![CDATA[

            import mx.core.UIComponent;

            private var loader:Loader;

             

            private function OnCreationComplete():void

            {

            var url : String ="assets/animation.swf";

            loader = new Loader();

             

            var request:URLRequest = new URLRequest(url);

            loader.load(request);

             

            loaderHolder.rawChildren.addChild(loader as DisplayObject);

            }

             

            private function onStop():void

            {

            var mc : MovieClip = loader.content as MovieClip;

            mc.stop();

            }

             

            private function onPlay():void

            {

            var mc : MovieClip = loader.content as MovieClip;

            mc.play();

            }

            ]]>

            </mx:Script>

            <mx:VBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">

            <mx:Canvas id="loaderHolder" width="500" height="500"/>

            <mx:Button label="Stop" click="onStop()"/>

            <mx:Button label="Play" click="onPlay()"/>

            </mx:VBox>

            </mx:Application>

             

             

            with Regards,

             

            Shardul Singh Bartwal

             

            • 3. Re: SWFLoader
              hitesh.rawat Level 1

              Thanks Shardul..........for the help.........

               

              I would prefer to go with the SWFloader...........primarily because i want to reduce the complexity of using action script as i'm new to it...........and as SWFLoader is available so as a component ....then why not use it..........

               

              however i tried......your code too.............but it gave me error ............. error #1009 .......while clicking the buttons.....both.....

               

               

               

               

              Thanks.....

              H.R.

              • 4. Re: SWFLoader
                ShardulSingh Level 3

                Hi,

                I think you dont change the name of your swf and dont mentioned the new path

                where I have written like this.

                 

                 

                var url : String ="assets/animation.swf";

                Change the path of your swf here.

                 

                 

                 

                with Regards,

                Shardul Singh Bartwal

                • 5. Re: SWFLoader
                  hitesh.rawat Level 1

                  No......

                  i changed that.....and showed the path to a local swf file. It also played the swf file.........after playing when tried stopping then i got that error #1009 .......I'm also trying to implement it using Movie clip class.........cause SWFloader doesn't provide a lot of help for user interaction........

                  • 6. Re: SWFLoader
                    ShardulSingh Level 3

                    cause SWFloader doesn't provide a lot of help for user interaction........

                     

                    How can this error come I have never used the swfLoader, Check your code.

                    This is working fine at other ends.

                     

                     

                    with Regards,

                    Shardul Singh Bartwal

                    • 7. Re: SWFLoader
                      jojothefunkyflex

                      Hi guys !

                       

                      I'm also trying to figure it out this problem. I have an animation made in swf and i just want to stop it at his end (even if i put stop(); on the last frame action).

                       

                      1 . Then I tried this solution (with SWFLOADER)

                      //-----------------------------------------------------------

                      // MXML file : index.mxml

                       

                      <?xml version="1.0" encoding="utf-8"?>
                      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" color="#000000" backgroundColor="#FFFFFF" borderColor="#FFFFFF" themeColor="#FFFFFF" backgroundGradientAlphas="[1.0, 0.0]" width="1000" height="865">
                         
                          <mx:Script source="script/index.as"/>
                         
                          <mx:SWFLoader id="monSwf" source = "assets/anim.swf" creationComplete="init(event)" horizontalCenter="13" verticalCenter="-23"/>
                          <mx:Button label="stop" click="stopAnim()"/>
                      </mx:Application>

                       

                       

                      // ActionScript file : INDEX.AS


                      import mx.controls.Alert;
                      import mx.controls.SWFLoader;
                      import mx.events.FlexEvent;

                       

                      private var flashMovie:MovieClip = new MovieClip();

                       

                      private function init(event:Event):void {
                           flashMovie = (event.currentTarget as SWFLoader).content as MovieClip;

                      }

                       

                      private function playAnim():void {
                          flashMovie.play();
                      }

                       

                      private function stopAnim():void {
                         
                          flashMovie.stop();
                      }

                      //-----------------------------------------------------------

                       

                      RESULT :

                      when I have this when I'm launching the project page :

                       

                      TypeError: Error #1009: Il est impossible d'accéder à la propriété ou à la méthode d'une référence d'objet nul.
                          at index/init()[C:\Documents and Settings\user\My Documents\Flex Builder 3\gk\src\script\index.as:10]
                          at index/__monSwf_creationComplete()[C:\Documents and Settings\user\My Documents\Flex Builder 3\gk\src\index.mxml:6]
                          at flash.events::EventDispatcher/dispatchEventFunction()
                          at flash.events::EventDispatcher/dispatchEvent()
                          at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src \mx\core\UIComponent.as:9298]
                          at mx.core::UIComponent/set initialized()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as :1169]
                          at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\frameworks\projects \framework\src\mx\managers\LayoutManager.as:718]
                          at Function/http://adobe.com/AS3/2006/builtin::apply()
                          at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framew ork\src\mx\core\UIComponent.as:8628]
                          at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framewo rk\src\mx\core\UIComponent.as:8568]

                       

                       

                      2. Then I tried this solution (with the LOADER)

                      //-----------------------------------------------------------


                      <?xml version="1.0" encoding="utf-8"?>
                      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                      layout="absolute" creationComplete="OnCreationComplete()">
                      <mx:Script>
                      <![CDATA[
                      import mx.core.UIComponent;
                      private var loader:Loader;
                      private function OnCreationComplete():void
                      {
                      var url : String ="assets/anim.swf";
                      loader = new Loader();
                      var request:URLRequest = new URLRequest(url);
                      loader.load(request);
                      loaderHolder.rawChildren.addChild(loader as DisplayObject);
                      }
                      private function onStop():void
                      {
                      var mc : MovieClip = loader.content as MovieClip;
                      mc.stop();
                      }
                      private function onPlay():void
                      {
                      var mc : MovieClip = loader.content as MovieClip;
                      mc.play();
                      }
                      ]]>
                      </mx:Script>
                      <mx:VBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
                      <mx:Canvas id="loaderHolder" width="500" height="500"/>
                      <mx:Button label="Stop" click="onStop()"/>
                      <mx:Button label="Play" click="onPlay()"/>
                      </mx:VBox>
                      </mx:Application>

                       

                       

                      RESULT :

                      when I have this when I click on the Stop button :


                      TypeError: Error #1009: Il est impossible d'accéder à la propriété ou à la méthode d'une référence d'objet nul.
                          at index/onStop()[C:\Documents and Settings\user\My Documents\Flex Builder 3\gk\src\index.mxml:19]
                          at index/___index_Button1_click()[C:\Documents and Settings\user\My Documents\Flex Builder 3\gk\src\index.mxml:30]

                       

                      Can  someone test that as I do and give us a feedback if it works or not.

                      Because I really need to know if it's the page or my framework.

                      • 8. Re: SWFLoader
                        Flex harUI Adobe Employee

                        If the loaded SWF is written for Flash Player 8 or earlier or using AS2, then you can't talk to it directly from Flex.  There are some third-party ways of handling this.  Search for as2interface or as3interface.

                         

                        Alex Harui

                        Flex SDK Developer

                        Adobe Systems Inc.

                        Blog: http://blogs.adobe.com/aharui

                        • 9. Re: SWFLoader
                          jojothefunkyflex Level 1

                          oh ! okay. Thank you to give me a solution.

                          I didn't think about that problems.

                          I'm gonna check tonight that, but I think I've generated the swf in flash v10 and AS3.

                          But to be sure I'm going to generate it again.

                           

                          keep in touch.

                          regards

                          • 10. Re: SWFLoader
                            jojothefunkyflex Level 1

                            I've checked if the swf generated was in AS3 and in Flash 9.

                            And actually it's in Flash 10 and in Action Script 3.

                             

                            But I have a warning when I publish the swf with Flash cs4:

                            WARNING: the actions associated with a button or MovieClip instances are not supported by ActionScript 3.0. No script associated with instances of objects will be taken into account.

                            (this message has been translate with google translate, I use French version of flash CS4)

                             

                            I want you to know that I have just one frame on the scene where i have action code, it's on the last one and the code is just :

                                 stop();

                             

                            but in flex that doesn't work (That's why I want to use the MovieClip solution with the swfloader)

                             

                            Then... I re-publish my swf file with AS2 and flash 9. AND IT WORKS !

                            Than I have to thank you HARUI !

                            I can stop and play my animation !

                             

                            now I want to play it just once and I want it to stop when it arrived at the end.

                            I'm trying to figure it out with the flashMovie.totalFrames property.

                            but it's more a algorithmic problem than a flex problem.... so Thank You anyway !