2 Replies Latest reply on Sep 18, 2010 8:20 AM by xchg_eax_ebx

    Load external swf

    xchg_eax_ebx

      Hi,

       

      I have external swf, which I want to load to flash application. I then want to moving through frames, scrolling, zooming with buttons. This is my code:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
          viewSourceURL="srcview" initialize="init();">
         <mx:Sprite id="pdfarea" x="0" y="0" height="500" width="500"></mx:Sprite>
         
          <mx:Button label="next" click="nextPage();"/>
          <mx:Button label="prev" x="70" click="prevPage();"/>
              <mx:Script>
                  <![CDATA[
                      import flash.display.Loader;
                      import flash.display.MovieClip;
                      import flash.net.URLRequest;

       

                      private var request:URLRequest;
                      private var loader:Loader;
                      private var viewport:MovieClip;

       

                      private function init():void {  
                      request = new URLRequest("dest.swf");
                          loader = new Loader();
                          loader.contentLoaderInfo.addEventListener( Event.INIT, loaded );
                          loader.load(request);
                      }

       

                     public function loaded(event:Event):void
                     {
                          pdfarea = loader.content;
                     }

       

                     private function nextPage():void {
                          pdfarea.nextFrame();
                     }

       

                     private function prevPage():void {
                          pdfarea.prevFrame();
                     }

       

                  ]]>
              </mx:Script>
      </mx:Application>

       

      So, it doesn't even compile :

       

      Error: Implicit coercion of a value with static type flash.display:DisplayObject to a possibly unrelated type flash.display:Sprite.

       

      What object I should use instead of sprite?

        • 1. Re: Load external swf
          xchg_eax_ebx Level 1

          I forgot to mention. I probalby can't use SWFLoader because later I want to implement encrypting that external swf file with as3crypto. So I will need to decrypt it first and then display.

          • 2. Re: Load external swf
            xchg_eax_ebx Level 1

            So, after little bit more research I've found some code on this forum. Little modified it looks like:

             

            <?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 var mc:MovieClip;

             

                    private function OnCreationComplete():void

             

                    {
                        var url:String ="dest.swf";
                        loader = new Loader();
                        var request:URLRequest = new URLRequest(url);
                        loader.load(request);
                        loaderHolder.rawChildren.addChild(loader as DisplayObject);
                    }

             

                    private function nextPage():void

             

                    {
                        mc = loader.content as MovieClip;
                        mc.nextFrame();
                    }

             

                    private function prevPage():void

             

                    {
                        mc = loader.content as MovieClip;
                        mc.prevFrame();
                    }

             

                    private function zoomIn():void
                    {
                        mc = loader.content as MovieClip;
                        mc._xscale++;
                        mc._yscale++;
                    }

             

                    private function zoomOut():void
                    {
                        mc = loader.content as MovieClip;
                        mc._xscale--;
                        mc._yscale--;
                    }
                    ]]>

             

                </mx:Script>

             

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

             

                    <mx:Canvas id="loaderHolder" width="500" height="500"/>
                    <mx:Button label="Prev" click="prevPage()"/>
                    <mx:Button label="Next" click="nextPage()"/>
                    <mx:Button label="+" click="zoomIn()"/>
                    <mx:Button label="-" click="zoomOut()"/>

             

                </mx:VBox>

             

            </mx:Application>

             

            It loads swf, prev/next button works but zooming does not. I also have no idea how to implement scrollbar