0 Replies Latest reply on Aug 19, 2009 3:00 PM by pratyus

    Text search in SWF

    pratyus

      I trying to build a simple application in flex in which I render a swf in the application. I want to enable user to search text using a textbox (id="SearchInpt") and button (id="SearchBtn").

       

      I have attached my test swf file

       

      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>