6 Replies Latest reply on May 18, 2010 9:07 PM by FTQuest

    how do i load a swf and take snapshots of that loaded swf?

    cyber0897 Level 1

      hey guys, so i have a multitude of swf's that i need to load into my application, and after loading them i need to take image snapshots of those swf's, to create a slides list.

       

      i know i can do somehting like this:

      var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(source);
      

       

       

      but the problem is, how do i know if the swf has loaded all the data within it???

       

       

      thanks in advance!

        • 2. Re: how do i load a swf and take snapshots of that loaded swf?
          FTQuest Level 3

          You can listen for the 'complete' event that is dispatched by SWFLoader once all the date is loaded.

           

          yourSWFLoader.addEventListener(Event.COMPLETE, yourHandler);

           

          HTH,

          FTQuest

          • 3. Re: how do i load a swf and take snapshots of that loaded swf?
            cyber0897 Level 1

            hi!, i've tried doing all the eventlisteners... but for some reason my swf just dosent get loaded...

            the code im trying is,

            private function init():void{
                 var swfLoader: SWFLoader = new SWFLoader();
                 swfLoader.addEventListener( Event.COMPLETE, handleSWFLoaded );
                 swfLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorEvent);
                 Alert.show("getting data");
                 try {
                      swfLoader.load(new URLRequest("http://test-broadcast.apxinsider.com/content/swf/home_strengthWeb.swf") );
                 } catch (error: Error) {
                      trace(error.message + "     Couldn't load file !" );
                      Alert.show(error.message);
                 }
            }
            
            private function handleSWFLoaded( event: Event ): void
            {
                 Alert.show("in handle swf");
            }
            
            private function securityErrorEvent(event:SecurityErrorEvent):void{
                 Alert.show("has security error event");
            }
            private function faultResult(event:FaultEvent):void{
                 Alert.show(event.fault.message);
            }
            
            private function takeSnapshot(source:IBitmapDrawable):ByteArray {
                 var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(source);
                 var imageByteArray:ByteArray = imageSnap.data as ByteArray;
                 return imageByteArray;
            }

             

             

            now my thinking is that i can just call the takeSnapShot function once my swf has loaded in teh handelSWFLoaded function...

             

            but for some reason when it gets to the function i get the following error:

             

            TypeError: Error #1009: Cannot access a property or method of a null obj

             

             

            is there another way i can loade my swf???

            • 4. Re: how do i load a swf and take snapshots of that loaded swf?
              FTQuest Level 3

              This error often refers to the wrong order of actions - you are trying to access something that hasn't been created yet.

               

              For example, looking quite briefly at your code I can't see where do you call the 'takeSnapShot()' function - it's defined, but isn't called.

              I'd suggest to start with the simplest version and then add the features.

              For example, call the load() function before trying to get the 'Complete' event.

              Simple iterative steps is the best approach.

               

              FTQuest

              • 5. Re: how do i load a swf and take snapshots of that loaded swf?
                cyber0897 Level 1

                well rightnow in my code im just trying to load the swf, im not up to the point of taking the snapshot yet since the swf hasnt been loaded yet... it gives me that error when im trying to load that swf...

                • 6. Re: how do i load a swf and take snapshots of that loaded swf?
                  FTQuest Level 3

                  OK.

                  Here is the starting point:

                   

                  <?xml version="1.0" encoding="utf-8"?>

                  <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                     xmlns:s="library://ns.adobe.com/flex/spark"

                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

                   

                   

                  <fx:Script>

                  <![CDATA[

                  import mx.controls.SWFLoader;

                   

                   

                   

                  private var swfLdr:SWFLoader;

                   

                  private function startSWF():void

                  {

                  swfLdr = new SWFLoader();

                  swfLdr.horizontalCenter = 0;

                  swfLdr.verticalCenter = 0;

                  swfLdr.source = "youFile.swf";

                  addElement(swfLdr);

                  }

                   

                   

                  ]]>

                  </fx:Script>

                  <s:Button x="50" y="50" label="start" click="startSWF()" />

                   

                  </s:Application>

                   

                  If this code gives you an error, you want to check that the swf address is correct and the swf itself is not corrupted.

                  From that point,  you start build your custom functionality - one step at a time!

                   

                  Sorry, HTH,

                  FTQuest