17 Replies Latest reply on Mar 29, 2010 1:31 PM by Darrell Loverin

    URGENT: SWFLoader unload issue

    Green Systems

      Hi Guys,

       

      I m writting a tutorial application with AIR2 Beta. This tutorial is meant to load different swf files one by one as user will select from given list. The swf files are created in Adobe Captivate 4 with AS3.

       

      The problem i m facing is that loaded swf files dont unload properly their sound keeps playing. When i load a second swf file (and unload first one) then the movie changes in SWFLoader display but sound keeps playing for first swf also. Same way if i load third swf, sound of previouse two files keeps playing along with third one. I have tried all possible solutions but still stuck in this issue from a long time.

       

      Expecting a solution at this adobe forum.

       

      Thanks,

       

      Asad Ijaz

        • 1. Re: URGENT: SWFLoader unload issue
          Darrell Loverin Level 4

          Call SWFLoader.unloadAndStop() to stop the sound.

          • 2. Re: URGENT: SWFLoader unload issue
            Green Systems Level 1

            Thanks for ur quick response.

             

            I have tried this method in my code but it is not working. Can u plz suggest when i should use this line of code. Currently i m using it right before i m loading any second swf file.

            • 3. Re: URGENT: SWFLoader unload issue
              Darrell Loverin Level 4

              That sounds right. Can you post a code snippet?

              • 4. Re: URGENT: SWFLoader unload issue
                Green Systems Level 1

                Before i put my code here i want to add one more thing which i forgot to mention initially and that may help u to understand the issue in a better way. I m loading swf files as "Binnary Data".

                • 5. Re: URGENT: SWFLoader unload issue
                  Darrell Loverin Level 4

                  I don't see where SWFLoader has a property to let you specify "Binary Data". How are you doing that?

                   

                   

                  -Darrell

                  • 6. Re: URGENT: SWFLoader unload issue
                    Green Systems Level 1

                    Here i m posting the specific code which i m using to load swf files as binnary data in SWFLoader.

                     

                      

                         private var binaryLoader:URLLoader;     
                         private var swfLoaded:Boolean = false;
                         //private var swfContent:MovieClip;
                                
                         private function init():void{
                             swfLFile.addEventListener(Event.INIT,onSWF_Load);
                             swfLFile.addEventListener(Event.UNLOAD,onSWF_Unload);
                             swfLFile.addEventListener(Event.COMPLETE, onSWF_LoadComplete); 
                         }
                       
                         public function onTreeClick(e:ListEvent):void{       
                             if(e.currentTarget.selectedItem.@name){
                                 try{
                                     var clickName:String = e.currentTarget.selectedItem.@Code;
                                     if(clickName.length > 0){
                                        CursorManager.setBusyCursor();
                              
                                        if(swfLoaded){
                                             swfLFile.unloadAndStop();                      
                                        }
                                         
                                        binaryLoader = new URLLoader();
                                        binaryLoader.addEventListener(Event.COMPLETE, onBinnaryLoad);
                           
                                        binaryLoader.dataFormat = URLLoaderDataFormat.BINARY;
                                        binaryLoader.load(new URLRequest(ENCRYPTED_SWF_URL));
                                 }
                            }
                            catch(err:Exponential){
                                 Alert.show("Unexpected error.");
                            }        
                          }
                       }
                          
                       private function onBinnaryLoad(e:Event):void{       
                          var binaryData:ByteArray = new ByteArray();
                        
                          binaryData = binaryLoader.data;
                          
                          if(binaryData.length != 0){
                               var loaderContext:LoaderContext = new LoaderContext();
                               loaderContext.allowLoadBytesCodeExecution = true;
                          
                               swfLFile.loaderContext=loaderContext;
                               swfLFile.load(binaryData);
                          }
                       } 
                       
                       private function onSWF_Load(oEvent:Event):void{    
                          //swfContent = oEvent.target.content;
                          swfLoaded = true;    
                       }
                       
                       private function onSWF_Unload(oEvent:Event):void{    
                          //swfContent.stop();
                          //swfContent.loaderInfo.loader.unload();    
                        
                          //binaryLoader.close();
                          //binaryLoader = null  
                        
                          swfLoaded = false;          
                       }
                       
                       private function onSWF_LoadComplete(oEvent:Event):void{
                          CursorManager.removeBusyCursor();
                       }
                    

                     

                    In this code swfLFile is a SWFLoader control. I hope other code is self explainatory. Let me know if there is any confusion.

                    • 7. Re: URGENT: SWFLoader unload issue
                      Darrell Loverin Level 4

                      That code worked for me once I hooked up the init() function to my application. Try setting a breakpoint on the unloadAndStop() call in SWFLoader to make sure it is being called. It should be around line 1641:

                       

                                              contentLoader.unloadAndStop(unloadAndStopGC);

                       

                      I'm running on Windows NT if that makes a difference.

                       

                       

                      -Darrell

                      • 8. Re: URGENT: SWFLoader unload issue
                        Green Systems Level 1

                        Darrell,

                         

                        I have already did it but i have checked once again code with breakpoint and all code is executing fine. UnloadAndStop line is reached and executed fully but sound still keeps playing. I m using Vista but i have tested it on XP also but same problem there too.

                         

                        Now wat i m feeling is that second swf file loads before first one is completely unloaded. Is it possible that we execute this code in a way that UnloadAndStop method of SWFLoader return execution control when complete unload is done?

                         

                        Asad

                        • 9. Re: URGENT: SWFLoader unload issue
                          Green Systems Level 1

                          Hi Darrell,

                           

                          So wat do u suggest next. I m waiting for ur response.

                           

                          I suggest that plz take up this matter with ur other team members so that we can have a permanent solution of this problem. If u can also approch Captivate technical personals to ask them, if we can do anything  while creating SWF files in Captivate that when those are unloaded they release all of the resources they are using.

                           

                          Thanks for ur help.

                           

                          Asad Ijaz

                          • 10. Re: URGENT: SWFLoader unload issue
                            Flex harUI Adobe Employee

                            BTW, you have to be using Flash Player 10 to get unloadAndStop to work.

                            • 11. Re: URGENT: SWFLoader unload issue
                              Green Systems Level 1

                              I have Flash Player 10 installed on my system and still my application is not working fine, it duplicates sounds of SWF files. Is there a way that i can programatically check (with AIR code) that SWFLoader is using which version of Flash Player? Plz remember i m developing a desktop application with AIR.

                               

                              Regards

                               

                              Asad Ijaz

                              • 12. Re: URGENT: SWFLoader unload issue
                                Flex harUI Adobe Employee

                                You can examine flash.system.Capabilities.version to see what version of the

                                player you are running.

                                 

                                Note that the first SWF loaded sets the API version for subsequent SWFs so

                                if you are using Flex 3 and did not specify -target-player=10 that may also

                                affect your ability to use unloadAndStop.

                                • 13. Re: URGENT: SWFLoader unload issue
                                  Green Systems Level 1

                                  I have checked flash player version with flash.system.capabilities.version and that is "WIN 10,1,50,334" while in both config files (air-config.xml and flex-config.xml) target player is set to version 10 i.e. <target-player>10</target-player>. One more thing which i have mentioned before but want to repeat again is i m using AIR2 Beta SDK and Flex Builder 3.

                                   

                                  I m really surprised that why it is not working. Now i have even compiled and created setup and installed it on another machine to check if it is working fine on anyother machine but it is not working there too.

                                   

                                  Asad Ijaz

                                  • 14. Re: URGENT: SWFLoader unload issue
                                    Flex harUI Adobe Employee

                                    Well, you could try Air 1.5.x just in case there's an AIR 2 bug.  If I were

                                    you I would start with a new project and just put in a button or two that

                                    allow you to switch your content and see if it fails there.

                                    • 15. Re: URGENT: SWFLoader unload issue
                                      Darrell Loverin Level 4

                                      At this point I think it would be best to write up a bug (http://bugs.adobe.com/jira) so we can take a look at your reproducable case.

                                       

                                       

                                      -Darrell

                                      • 16. Re: URGENT: SWFLoader unload issue
                                        Green Systems Level 1

                                        Hi,

                                         

                                        To make sure that if it is an issue with AIR2, i have created a separate AIR project with AIR1.5. This time the senerio is little different.

                                         

                                        1. I played first SWF, everything worked fine

                                        2. I played second SWF, voice stopped for first SWF and second loaded fine means everything worked fine

                                        3. I played first SWF again, now here the problem came. Voice of second SWF remained playing and over lapped first ones

                                        4. After it wat ever i did voice did stop

                                         

                                        Following is my code for this test. Plz have a look and let me know if i should post it in bugs list?

                                         

                                        <?xml version="1.0" encoding="utf-8"?>
                                        <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="745">
                                         
                                        <mx:Script>
                                         <![CDATA[   
                                          
                                          import flash.events.Event;
                                          import flash.net.URLLoader;  
                                          import flash.utils.ByteArray;  
                                          import flash.events.*;
                                          
                                          private var binaryLoader:URLLoader;
                                          private var SWF_URL:String;
                                          
                                          private function PlayFirst():void{
                                           SWF_URL = "DMS_CS4_L1-1.swf";          
                                              
                                              swfLFile.unloadAndStop();
                                              
                                              binaryLoader = new URLLoader();
                                           binaryLoader.addEventListener(Event.COMPLETE, onBinnaryLoad);
                                           
                                           binaryLoader.dataFormat = URLLoaderDataFormat.BINARY;
                                           binaryLoader.load(new URLRequest(SWF_URL));
                                          }
                                          
                                          private function PlaySecond():void{
                                           SWF_URL = "DMS_CS4_L1-2.swf";          
                                              
                                              swfLFile.unloadAndStop();
                                              
                                              binaryLoader = new URLLoader();
                                           binaryLoader.addEventListener(Event.COMPLETE, onBinnaryLoad);
                                           
                                           binaryLoader.dataFormat = URLLoaderDataFormat.BINARY;
                                           binaryLoader.load(new URLRequest(SWF_URL));
                                          }
                                          
                                          private function onBinnaryLoad(e:Event):void{       
                                           var binaryData:ByteArray = new ByteArray();
                                           
                                           binaryData = binaryLoader.data;
                                           if(binaryData.length != 0){
                                            
                                            var loaderContext:LoaderContext = new LoaderContext();
                                            loaderContext.allowLoadBytesCodeExecution = true;
                                             
                                            swfLFile.loaderContext=loaderContext;
                                            swfLFile.load(binaryData);
                                           }
                                          }
                                         ]]>
                                        </mx:Script>
                                         <mx:SWFLoader id="swfLFile" scaleContent="true" width="721.5" height="566" trustContent="true" showBusyCursor="true" y="10" x="10"/>
                                         <mx:Button x="208" y="608" label="First" click="PlayFirst()"/>
                                         <mx:Button x="290" y="608" label="Second" click="PlaySecond()"/>
                                        </mx:WindowedApplication>
                                        
                                        
                                        • 17. Re: URGENT: SWFLoader unload issue
                                          Darrell Loverin Level 4

                                          Yes, please file a bug report.