10 Replies Latest reply on Sep 17, 2009 10:30 AM by <patel:tanmay />

    Movie clip

    hitesh.rawat Level 1

      Hello ,

       

      I started with using SWFloader to play the external swf's, however, i stuggled to pause, stop and do other controls regarding the sound.....also.......so i'm switching to movie clip.........as it has these in-built methods..........

       

       

      however, i'm getting error while playing the .swf.   I'm pasting the code below.....please check why am i getting error .......# 1034

       

      TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Loader@48847e1 to mx.core.IUIComponent

       

       

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >



      <mx:Script>
          <![CDATA[
              import flash.display.Loader;
             
             
          private function init(e:Event):void
          {
         
               
      text.visible = true;
                 text.text = "hey";

                
                 var mc:MovieClip = new MovieClip();
                 var load:Loader = new Loader();
                
                 var req:URLRequest = new URLRequest("deckAS32.swf");
                
                 load.load(req);
               mc .addChild(load);
                
              
                     
          }
         
         
         
         
          ]]>
      </mx:Script>

          <mx:LinkButton x="318" y="455" label="Play" id="play" click="init(event)"/>
         
          <mx:TextArea id="text"  x="303" y="138" width="281" height="187" visible="false"/>
       
         
        
      </mx:Application>

        • 1. Re: Movie clip
          <patel:tanmay />

          You can not add display objects to the flex containers - Application, canvas etc - that does NOT implement mx.core.IUIComponent

           

          So, to add the movie clip you can either make a UIComponent and call it's addChild() method to add movieclip within it.

           

          That is..

           

          var uiComponent:UIComponent = new UIComponent();

          addChild(uiComponent);

           

          var mc:MovieClip = new MovieClip();

          uiComponent.addChild(mc);

           

           

          Or... alternatively u can make use of rawChildren property

           

          like...

           

          this.rawChildren.addChild(mc);

          • 2. Re: Movie clip
            hitesh.rawat Level 1

            thanks,

             

            I tried this with your example..........this compiles however it is not playing the SWF, also it doesn't gives any run time error

             

             

              var uicomponent:UIComponent = new UIComponent();
                      addChild(uicomponent);
                     
                     
                   
                     
                       var mc:MovieClip = new MovieClip();
                       uicomponent.addChild(mc);
                      
                      
                       var load:Loader = new Loader();
                      
                       var req:URLRequest = new URLRequest("deckAS32.swf");
                      
                       load.load(req);
                       mc.addChild(load);
                      

            • 3. Re: Movie clip
              <patel:tanmay /> Level 1

              You actually need not to use MovieClip here i think.

               

              The following should help...

               

                          private function onCreationComplete():void
                          {
                              var uicomponent:UIComponent = new UIComponent();
                              addChild(uicomponent);
                                
                              var loader:Loader = new Loader();
                              var req:URLRequest = new URLRequest("xyz.swf");

                              loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadingCompleted);
                              loader.load(req);
                             
                              uicomponent.addChild(loader);
                             
                          }
                         
                          private function loadingCompleted(event:Event):void
                          {
                              (loader.content as MovieClip).play()
                          }

              • 4. Re: Movie clip
                hitesh.rawat Level 1

                Thanks,

                 

                however this code.....is giving me a comile time error saying on line

                 

                (loader.content as MovieClip).play()

                 

                saying ACCESS TO UNDEFINED PROPERTY LOADER

                • 5. Re: Movie clip
                  <patel:tanmay /> Level 1

                  oops...

                   

                  It should be like

                   

                  (event.target.content as MovieClip).play()

                   

                  and ofcourse it assumes that the swf you are loading is from flash and not flex

                  • 6. Re: Movie clip
                    hitesh.rawat Level 1

                    it worked...................

                     

                     

                    i was going through the adobe flex book.........it had this topic where they showed how to add external swf.............

                     

                    var request:URLRequest = new URLRequest(“http://www.[yourdomain].com/externalSwf.swf”);
                    var loader:Loader = new Loader()
                    loader.load(request);
                    addChild(loader);

                     

                    these steps should be enough as they said..........but don't think it was that easy.......think it was just for flash.......

                    • 7. Re: Movie clip
                      hitesh.rawat Level 1

                      Hi,

                       

                      Thanks for the above answer, it worked........after that i tried stopping the swf which worked first......but a few days back i made some changes to that........to which i'm not able to revert back meaning ......stop function is not working right now.

                       

                       

                      this is the function i created.......its similar to what you did last time for play

                       

                      where mc is just a variable with no type declaration

                       

                      this is the play function which works fine

                       

                        private function loadingCompleted(event:Event):void
                                  {
                                      (event.target.content as MovieClip).play();
                                       mc = event.target.content ;
                                      
                                        playText.visible = true;
                                       playText.text = event.target.content;
                      // i used the text box to trace the value of mc
                                  }


                      This is the stop function which is not working

                       

                      private function onStop():void
                         {

                       

                        T.visible = true; 
                         T.text = mc;
                            // i used the text box to trace the value of mc
                        
                        
                         mc.stop();
                        
                        
                         }

                       

                       

                      I compared the values of variable mc at both location................which was the same....... [object Timeline0_e5b88cb7689f484fba23ce36e5d23f36]

                       

                      but at the first place it is playing the swf, its not doing the same in the second function to stop the swf..............

                       

                       

                      Thanks.......

                       


                      • 8. Re: Movie clip
                        hitesh.rawat Level 1

                        I'm sorry for the above post.................but the Flex builder some time really irritates me.......the code is working now......don't know why it wasn't earlier..............i mean i just restarted the Flex builder.....and it worked.

                        • 9. Re: Movie clip
                          hitesh.rawat Level 1

                          hi...................

                           

                          i used the above code to play the swf.............i also need help to stop it.......

                           

                          i tried with this......however it won't work......... Error #1069: Property content not found on mx.controls.Button and there is no default value.

                          I think its not finding the object........however could understand....if the same is working for playing the swf.

                           

                          Thanks.....

                           

                           

                           

                          private function loadingCompleted(event:Event):void
                                      {
                                          
                                          if(loader.content == null)
                                          {
                                             
                                          (event.target.content as MovieClip).play();
                                           mc = event.target.content ;
                                          
                                          }
                                          
                                      }
                                    
                                      private function onStop(event:Event):void
                                      {
                                     
                                      (event.target.content as MovieClip).stop();
                                     
                                     
                                     
                                      }

                          • 10. Re: Movie clip
                            <patel:tanmay /> Level 1

                            I think you are getting this error while clicking on "Stop" button... i mean while stopping the loaded swf.

                             

                            Now in that code you can not use the event.target since it will return the button you have clicked!

                             

                            so in this case you need to have the loader class level access. That is, it needs to be a class member rather then a method variable so that you can access it in multiple methods in the class.

                             

                            Hope, you have understood that. Refer to flash events for more details on event.target.