10 Replies Latest reply on Apr 27, 2011 1:40 AM by JSujubala-nZao4n

    Selecting text from swf file

    pratyus

      Hi,

       

      I am new to flex. I trying to build a simple application in flex in which a user clicks a button, to choose a file (.swf) from a file selection box, which is rendered in the application. I want to enable user to select text using mouse cursors from the loaded swf file. Can some one point me to resources or sample code that would help me achieve this.. Thanks!

       

      below is the code for loading the file:

       

      <mx:Script>
              <![CDATA[
                
                  public var refUploadFile:FileReference = new FileReference();
                  public var swfFileName:String = new String ();
                 
                  private function addFile() : void

                     {
                     refUploadFile.browse();
                     refUploadFile.addEventListener(Event.SELECT, selectedFileShow);
                     }

                 private function selectedFileShow(event:Event):void

                     {
                     fileName = refUploadFile.name;
                     swfFileName = "D:/"+ refUploadFile.name;  //considering the file resides in D:
                     }
              ]]>
          </mx:Script>
             
          <mx:Button id="browse" x="69" y="21" label="Browse" click="addFile()" />

         <mx:Image id ="img" source="{swfFileName}" y="40" >
         
         </mx:Application>

        • 1. Re: Selecting text from swf file
          Madhav Subedi Level 4

          Some points:

           

          1. you should declare swfFileName Bindable.

           

          2. you cannot do like swfFileName = "D:/"+ refUploadFile.name; in Flex Applications; rather you may upload that file to server in a specific location and changer your swfFileName accordingly.

           

          3. AFAIK, selecting the test of loaded swf would depend on that swf file, which control is used there; not your application.

          1 person found this helpful
          • 2. Re: Selecting text from swf file
            pratyus Level 1

            Is there a way for tell what control are provided by the swf file.

             

            Ihave attached the file, i am using with this post.

            • 3. Re: Selecting text from swf file
              Madhav Subedi Level 4

              with the swf you attached, i dont see any possibilities to let users select the text.

              1 person found this helpful
              • 4. Re: Selecting text from swf file
                pratyus Level 1

                I want to enable user to search text using a textbox (id="SearchInpt") and button (id="SearchBtn").

                 

                I have also attached my test swf

                I am able to load the swf file into the application, but search always fails. Below is the code I am using

                Am I missing something in the code. I will be grateful for any help or pointers to resources.

                Thanks!

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
                    
                   
                    <mx:Script>
                        <![CDATA[
                          
                            import mx.controls.SWFLoader;
                            import mx.controls.Label;
                            import flash.text.TextSnapshot;
                           
                            public var snapText:TextSnapshot;
                                      
                            private function doSearch() : void 
                                {
                                snapText = img.textSnapshot;
                                if (SearchInpt.text != '' && SearchInpt.text.length > 1) {
                                         var textPos:int = snapText.findText(0, SearchInpt.text, false);
                                        snapText.setSelected( 0, snapText.charCount, false );
                       
                                if (textPos > 0) {
                                     do {
                                        snapText.setSelectColor( 0xFFEF00 );
                                        snapText.setSelected( textPos, textPos + SearchInpt.text.length, true );
                                         textPos = snapText.findText(textPos + SearchInpt.text.length, SearchInpt.text, false);
                                         }
                                    while (textPos > 0)
                                    }
                                else
                                    {
                                    Alert.show( "Not found.", "Information" );                
                                     }
                                }
                                else
                                    {
                                    snapText.setSelected( 0, snapText.charCount, false );                   
                                    }

                 

                                }
                        ]]>
                    </mx:Script>
                       
                        <mx:Panel title="SWF Player" y = "50" width="100%" height="100%">
                             <mx:Canvas id="canvas" width="100%" height="100%">
                                    <mx:TextInput x="10" y="21" width="80" id="SearchInpt"/>
                                   <mx:Button x="98" y="21" label="Search" id="SearchBtn" click = "doSearch()"/>
                                    <mx:SWFLoader id ="img" source="C:/testswf.swf" y="50" />
                             </mx:Canvas>
                     </mx:Panel>
                </mx:Application>

                • 5. Re: Selecting text from swf file
                  Madhav Subedi Level 4

                  the snapText doesnot seem to load any texts...

                   

                  private function doSearch():void

                  {

                  snapText=img.textSnapshot;

                  Alert.show(snapText.charCount.toString());// displays 0.

                  • 6. Re: Selecting text from swf file
                    pratyus Level 1

                    I have tried that.. it would also give me the same result,  0

                     

                    Do you see anything wrong in my code.. is there a better way to do this? or a way to work around it?

                    • 7. Re: Selecting text from swf file
                      joaocoelho

                      TextSnapshot only works with static non selectable text fields, seems to be a "feature" of the player, I would also be interested in knowing about any workaround anyone may find.

                       

                      Thanks!

                      • 8. Re: Selecting text from swf file
                        pratyus Level 1

                        snapText = (img.content as MovieClip).textSnapshot;

                         

                        This is what i was missing.

                        • 9. Re: Selecting text from swf file
                          Luiz Barros
                          You got to put the search work?
                          I am new to flex and need a search where you can find text within a swf.

                           

                          Can guide me how he?
                          • 10. Re: Selecting text from swf file
                            JSujubala-nZao4n

                            I am also facing the same problem so anyone guide us...!!!