Time for action – adding the links card's init handler

Before proceeding, make sure that you are happy with the functions in the test stack and that you have copied them to the WebScraper stack script using the following steps:

  1. Go to the Links card of the WebScraper stack.
  2. Edit the card script and add these global variables and init function:
    global gPageHTML,gLinks
    
    on init
    if the platform is "iphone" or the platform is "android" then
      put getLinks(gPageHTML) into gLinks
      if the number of lines in gLinks = 0 then
         answer "There are no links in this page!"
      else
         mobilePick gLinks,0
         if the result > 0 then
          put the result into tLinkLine
          put line tLinkLine of gLinks into tLink
          go card "Browser"
          set the mgText of group "url" to tLink
          set the Text of field "NavBar" to "Browser"
          mobileControlSet "Page", "url", the mgText of group "url"
          end if
        end if
      end if
    end init
  3. Do a Test of the app.
  4. In the iPhone Simulator or Android device, if that's what you're using, change the URL to http://www.runrev.com/ and select the Go button.
  5. When the page is loaded, select the Links tab button.
  6. You should now be looking at the list of links from the RunRev page; only this time, it's presented in a native picker list.
  7. Select a link from the list and then Done.
  8. You will be taken back to the Browser card with the linked page loaded.

What just happened?

The card script we entered does the same job as the button in the test stack; in that, it calls to the stack functions to get a list of links. Here, rather than putting the list into a plain field, we used LiveCode's ability to open a native picker control using the line:

mobilePick gLinks,1

The required parameters of this function are a list of items to be shown and an index position to be the one that is selected. By entering 1, the first item is selected by default. The result that comes back from the picker is an index of the item that was selected, and we can use this to look up the matching line in the gLinks variable.

The remaining lines take us back to the Browser card, set the URL to be loaded, and also change the NavBar to reflect the card name.

The Text card

Making the Text card work is a lot simpler, but includes an unbelievably complex regular expression line, which can be found at:

http://stackoverflow.com/questions/3951485/regex-extracting-readable-non-code-text-and-urls-from-html-documents

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset