6 Replies Latest reply: Aug 23, 2011 6:50 AM by The Feldkircher RSS

    HELP would be awesome!!

    Gaff2156 Community Member

      Hi guys !!

       

      I am working o a jargon buster for a college project.

       

      I have written up an (External) XML document like this:

       

      <Items>

            <Query>Rip</Query>

             <answer>to copy files from a disc onto a computer</answer>

       

      </Items>

       

      Basically the user inputs their query into a editable text field and then flash searches the xml for the query and returns an

      answer into a readable text field below.

       

      My problem is how do I get flash to do that??

       

      Thanks in advanced.

        • 1. Re: HELP would be awesome!!
          The Feldkircher Community Member

          Hi

           

          First and most difficult is to be able to Search on whatever the User types in - this is not the most secure or easily searchable method.

           

          I'd suggest; to make life easier on yourslf - limit the Search criteria by using a drop-down list populated with your <query>Rip</query>

          The User is then limited only to the selection in the list  - and the result can be instantly displayed in a dynamic textfield.

           

           

          Hope it helps

          • 2. Re: HELP would be awesome!!
            Gaff2156 Community Member

            Point taken but your proposal has its downsides.... this is a project which I hope to add to the jargon xml file so by doing this way I would not have to keep updating the drop down list... Its a good idea but I don't think its suited for this project....

             

             

            this is what I've come up with so far:

             

             

             

            import fl.motion.MotionEvent;

             

            var xml:XML;
            var loader:URLLoader = new URLLoader();
            //loader.addEventListener(Event.COMPLETE, search);/// --- dont think I need this line ----
            loader.load(new URLRequest("jarb.xml"));




            search_btn.addEventListener(MouseEvent.CLICK, initsearch)

             

            function initsearch(evtObj:MotionEvent):void{
               
            answer_txt.text   = XML.items.Query.(text().toString().toLowerCase() ==   input_txt.text.toLowerCase()).parent().answer.text().toString();
                }

             

             

            But unfortunatley I am getting this returning  error :

             

            TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::MouseEvent@2912af51 to fl.motion.MotionEvent.

             

             

            ANY IDEAS??

            • 3. Re: HELP would be awesome!!
              The Feldkircher Community Member

              Hi

               

              The drop-down list would be DYNAMIC - automatically populated by your XML.

               


              Google 'comboBox dataProvider'

               

              Hope it Helps

              • 4. Re: HELP would be awesome!!
                The Feldkircher Community Member

                OK Try this

                 

                Drag a ComboBox from the Components Panel onto the Stage and give it a Instance name of combo in the Properties Panel.

                Create a Dynamic TextField on the Stage with an Instance name of answer in the Properties Panel.

                 

                Copy and Paste this into the Actions Panel.

                 

                import flash.net.URLLoader;
                import flash.net.URLRequest;

                 

                var xml:XML;
                var urlRequest:URLRequest = new URLRequest("jargonBuster.xml");
                var urlLoader:URLLoader = new URLLoader(urlRequest);
                urlLoader.load(urlRequest);

                 

                urlLoader.addEventListener(Event.COMPLETE, xmlDataLoaded,false,0,true);

                 

                function xmlDataLoaded(e:Event)
                {
                xml = new XML(e.target.data);

                for each(var qry:XML in xml.items.Query)
                {
                     combo.addItem({label: qry});
                }
                answer.text = xml.items[0].answer;
                combo.addEventListener(Event.CHANGE, comboChanged, false, 0, true);
                }

                 

                function comboChanged(e:Event)
                {
                    answer.text = xml.items[e.target.selectedIndex].answer;
                }

                 

                jargonBuster.xml looks like this:-

                 

                <?xml version="1.0"?>
                <jargonBuster>
                  <items>
                    <Query>HDD</Query>
                    <answer>Hard Disk Drive</answer>
                  </items>
                  <items>
                    <Query>USB</Query>
                    <answer>Universal Serial Bus</answer>
                  </items>
                  <items>
                    <Query>Rip</Query>
                    <answer>to copy files from a disc onto a computer</answer>
                  </items>  
                </jargonBuster>

                 

                Now when you select and item in the list the answer appears in the textfield.

                 

                Hope it helps.

                • 5. Re: HELP would be awesome!!
                  Gaff2156 Community Member

                  That was actually really helpful!!!

                   

                   

                   

                  Just wondering you see when you run this as is the user has to scroll down through all the possible queries???

                   

                  OK so how would we change the input field say of my original code so that the user inputs their query---- but while they are inputing the query your dropdown combobox is implemented so the user if the are not finished typing (a bit like the google search system) could pick the predefined listed item...

                   

                  THEN the result is displayed in the bottom box after they hit my search button....

                  • 6. Re: HELP would be awesome!!
                    The Feldkircher Community Member

                    Glad it helped:-

                     

                    But now your asking for a Predictive Text System - I think you would have to implement a Dictionary based lookup system.

                    I'm not familiar with this so not very helpful there.

                     

                    However: you could extend the drop-down list method -

                     

                    Add a Category Attribute to your jargonBuster.xml this would then be your fisrt choice drop-down.

                     

                    Such as: Email

                                   Hardware

                                   Internet

                                   Software

                     

                    <item cat="Email">

                    <query>Spam</query>

                    <answer>Unsolicited Email</answer>

                    </item>

                    <item cat="Hardware">

                    <query>HDD</query>

                    <answer>Hard Disk Drive</answer>

                    <item cat="Email">

                    <query>Junk Mail</query>

                    <answer>Like Spam - but more annoying</answer>

                    </item>

                     

                    Then in a second drop-down list you can have all the queries related to the choice in the first list.

                     

                    I am not trying to dissuade you from the way you want to do it - its just most systems use this type of drill-down method.

                     

                    Hope it helps