5 Replies Latest reply on Apr 14, 2010 6:38 AM by kglad

    How to test to see if inputted swf exists?

    celebritymusic Level 1

      Hi

       

      I have an input field that asks for a .swf name - you enter the name, hit SUBMIT, and Flash loads that .swf onto the screen.

       

      I've coded for an error to appear if the user doesn't input anything, but how to I test to see if the swf exists, and if not, return an error?

       

      I have a function called onSwfLoad that runs when the swf loader finishes, triggered by an Event.COMPLETE in the swf loader event listener - is there something I can put in an if statement there to test if the swf loader found a file?

       

      Thnaks

       

      Shaun

        • 1. Re: How to test to see if inputted swf exists?
          kglad Adobe Community Professional & MVP

          there's an ioerror event you can use.

          • 2. Re: How to test to see if inputted swf exists?
            celebritymusic Level 1

            Hi kglad

             

            How does IOErrorEvent.IO_ERROR fit into the following code?  I applied it as an event listener to the loader loading the swf, but I'm doing something wrong:

             

            loadSwfBut.addEventListener("mouseDown", sendData)
            function sendData(evt:Event)  {
                if(loadSwf.text !=""){
                   
            var Xpos:Number = 0;
            var Ypos:Number = 100;
            var swf:MovieClip;
            var loader:Loader = new Loader();

             

            var defaultSWF:URLRequest = new URLRequest(loadSwf.text);

             

            loader.load(defaultSWF);
            loader.x = Xpos;
            loader.y = Ypos;
            addChild(loader);
                           
                    loader.addEventListener(Event.COMPLETE, dataOnLoad);
                    loader.addEventListener(IOErrorEvent.IO_ERROR, errorLoading);
                   
                           
                } else status_txt.text = "All fields are mandatory"
            }

             

            function errorLoading(event:IOErrorEvent):void {
                status_txt.text = "nup"
            }

             

            function dataOnLoad(evt:Event){
                status_txt.text = "yep"
            }


            stop()

             

             

            Thanks kglad

             

            Shaun

            • 3. Re: How to test to see if inputted swf exists?
              kglad Adobe Community Professional & MVP

              the loader class doesn't have any events.  you use the contentloaderinfo property of your loader to get a loaderinfo reference and that has the events you need:

               


               

              loadSwfBut.addEventListener("mouseDown", sendData)
              function sendData(evt:Event)  {
                  if(loadSwf.text !=""){
                     
              var Xpos:Number = 0;
              var Ypos:Number = 100;
              var swf:MovieClip;
              var loader:Loader = new Loader();

               

              var defaultSWF:URLRequest = new URLRequest(loadSwf.text);

               

              loader.load(defaultSWF);
              loader.x = Xpos;
              loader.y = Ypos;
              addChild(loader);
                             
                      loader.contentLoaderInfo.addEventListener(Event.COMPLETE, dataOnLoad);
                      loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorLoading);
                     
                             
                  } else status_txt.text = "All fields are mandatory"
              }

               

              function errorLoading(event:IOErrorEvent):void {
                  status_txt.text = "nup"
              }

               

              function dataOnLoad(evt:Event){
                  status_txt.text = "yep";
              }


              stop();

              1 person found this helpful
              • 4. Re: How to test to see if inputted swf exists?
                celebritymusic Level 1

                Cheers kglad

                 

                I'll try that in a few minutes.

                 

                Much appreciated mate.

                 

                Shaun

                • 5. Re: How to test to see if inputted swf exists?
                  kglad Adobe Community Professional & MVP

                  you're welcome.

                  1 person found this helpful