14 Replies Latest reply on Aug 31, 2013 9:18 PM by Flex harUI


    Yue_Hong Level 1



      I want to place a swfloader with width = 500, height = 400 inside the flex project to load multiple swf and images. Here I want to ask:


      1. How to prevent the swfloader from displaying content of flash outside the fixed dimension?

      2. How is it possible to know when the playback of swf reach the end and perform some action?



        • 1. Re: SWFLoader!!!!!!!!!
          Flex harUI Adobe Employee

          1. Apply a mask or scrollrect, or put it in a container that does clipping.

          2. There is no way to know in the general case.  If the SWF is animating

          birds flying or balls bouncing, there's now way to know when it has stopped.

          If the SWFs have a particular behavior it might be possible to know.

          1 person found this helpful
          • 2. Re: SWFLoader!!!!!!!!!
            pradeep reddy




            Try to use maintainAspectRatio and scaleContent properties of SWFLoader it will adjust the content..!


            if you take the SWF as a movie clip..! we can calculate the totaltime..!


            Hope this will help you..!





            • 3. Re: SWFLoader!!!!!!!!!
              Yue_Hong Level 1

              Thanks a lot for your reply, Flex harUI.


              How is it that SWF to have particular behavior? You mean something like stop() in swf the swfloader is able to detect it? How? Because I need to have the SWFLoader automatically loads another swf / image file when the playback of current swf file ends. Thanks.

              • 4. Re: SWFLoader!!!!!!!!!
                Flex harUI Adobe Employee

                If, for example, you know that all SWFs are just timeline animations with no

                script, you can watch for currentFrame == frameCount.


                If you know every SWF has a video component referenced as "videoComponent",

                you can get the video component and watch for the video to end.


                It all depends on what assumptions you can make.

                • 5. Re: SWFLoader!!!!!!!!!
                  Yue_Hong Level 1

                  Thanks. But how can I get the current frame?

                  • 6. Re: SWFLoader!!!!!!!!!
                    Flex harUI Adobe Employee


                    • 7. Re: SWFLoader!!!!!!!!!
                      Yue_Hong Level 1

                      Thanks for your reply. But when I try to run the project I receives the error:


                      TypeError: Error #1009: Cannot access a property or method of a null object reference.
                          at Main/loader_enterFrameHandler()[D:\Lab\Flex Project\experiment\SWF Loader\src\Main.mxml:21]
                          at Main/__loader_enterFrame()[D:\Lab\Flex Project\experiment\SWF Loader\src\Main.mxml:35]



                      Here is my code:



                      <?xml version="1.0" encoding="utf-8"?>
                      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"




                                  protected function loader_enterFrameHandler(event:Event):void
                                      framedisplay.text = MovieClip(loader.content).currentFrame.toString();



                                  <s:VerticalLayout paddingLeft="10" paddingTop="10"/>
                          <mx:SWFLoader id="loader" source="assets/animation.swf" width="400" height="300" maintainAspectRatio="true" scaleContent="true" scrollRect="{new Rectangle(0, 0, loader.width, loader.height)}" enterFrame="loader_enterFrameHandler(event)"/>
                              <s:Label id="framedisplay" text="display swf current frame."/>



                      How should I fix it? Where to put MovieClip code? Thanks.

                      • 8. Re: SWFLoader!!!!!!!!!
                        Flex harUI Adobe Employee

                        Loader.content will be null until the SWF is loaded.

                        • 9. Re: SWFLoader!!!!!!!!!
                          Yue_Hong Level 1

                          Thanks. I have put the function under complete="loader_completeHandler(event)" to load the MovieClip(loader.content).currentFrame script. However, it still shows up error message...


                          It would be nice if there is a sample code of it. Thanks.

                          • 10. Re: SWFLoader!!!!!!!!!
                            Flex harUI Adobe Employee

                            I think you have to use enterFrame because the complete handler will only

                            fire once.  Just test if loader.content == null and exit.

                            • 11. Re: SWFLoader!!!!!!!!!
                              Yue_Hong Level 1

                              I have tried, but still receives error message on the startup.


                              Here is the error message:


                              TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::AVM1Movie@610d1f1 to flash.display.MovieClip.
                                  at Main/loader_enterFrameHandler()[F:\Flex Project\experiment\SWF Loader\src\Main.mxml:24]
                                  at Main/__loader_enterFrame()[F:\Flex Project\experiment\SWF Loader\src\Main.mxml:44]



                              My code now is:


                              if (loader.content != null){
                                                  framedisplay.text = MovieClip(loader.content).currentFrame.toString();

                              • 12. Re: SWFLoader!!!!!!!!!
                                Flex harUI Adobe Employee

                                If you are loading SWFs not published for AS3 you will need a more

                                sophisticated solution.  Google for as3interface.

                                • 13. Re: SWFLoader!!!!!!!!!
                                  Bikrant Singh



                                  I have a same problem so how can i resolve it.

                                  I have a one problem regarding this. I have multiple swf file and it loads one by one like if first one is finished then next will be loaded.

                                  I use enterFrame event for checking the frame.

                                  My problem is that it all working fine in windows pc but when i install this in mac, the swf file play in slow motion and it consume the memory and the mac pc become hangs.


                                  How can i solve this.

                                  • 14. Re: SWFLoader!!!!!!!!!
                                    Flex harUI Adobe Employee

                                    Use performance profiler to see what is taking all the time.