Time for action – setting up the Keepers card

  1. Go to the Keepers card and create a MobGUI button for Prev, Next, and Play Media. Make a MobGUI Multiline field and name it mediaURL. Be sure to uncheck the Auto delete option, so that it keeps the URL data when we change cards. Also uncheck the Editable option. You should now have something looking like the following screenshot:
    Time for action – setting up the Keepers card
  2. Add these lines to the mouseUp handler of the Prev button:
      if the number of this card is > 5 then
        go previous
      end if
  3. Add these lines to the mouseUp handler of the Next button. Note that - 1 is used since the last card is the MobGUI card:
      if the number of this card < the number of cards - 1 then
        go next
      end if
  4. Add this line to the Play Media button's mouseUp handler:
      showMedia the mgText of group "mediaURL"
  5. Select the four controls and Group them. Check the box that says Behave like a background. Name the group keeperbuttons.
  6. Edit the script of the new group. Add this refresh handler:
    on refresh
      set the itemdelimiter to "."
      if char 1 of the last item of the mgText of group "mediaURL" is "m" then
        show group "Play Media"
      else
        hide group "Play Media"
        showMedia the mgText of group "mediaURL"
      end if
    end refresh
  7. We need to go back and add things to the Media card.
  8. Go to the Media card and add a MobGUI button. Set the name and label to Keep Media.
  9. One tricky thing is that media will play full screen on smaller screens and by the time you see the Keep Media button, the video has already gone away. We can work around this by storing the URL of the last shown media in a global variable.
  10. In the Media card script, change the init function, so that the later lines read like this:
    if the result > 0 then
      put the result into tMediaLine
      put line tMediaLine of gMediaList into gLastMedia
      showMedia gLastMedia
    end if
  11. Change the global variable declaration line to include the gLastMedia variable.
  12. Set the mouseUp handler of the Keep Media button to be this:
    on mouseUp
      global gLastMedia
      go  card (the number of cards -1)
      if the mgText of group "mediaURL" is not empty then
      new card
      end if
      set the mgText of group "mediaURL" to gLastMedia
      save stack "WebScaper" as (specialFolderPath("documents") & "/WebScraper.livecode")
      send "refresh" to group "keeperButtons"
    end mouseUp
  13. Now, only one last step is required for the stack to save the media. We need to create a launcher app like we did earlier in this chapter. Create a stack named LaunchScraper with the following stack script:
    on openStack
      set the defaultFolder to specialFolderPath("Documents")
      if there is not a file "WebScraper.livecode" then
        put the filename of this stack into masterfile
        set the itemdelimiter to "/"
        put "WebScraper.livecode" into the last item of masterfile
        put specialFolderPath("engine") & "/WebScraper.livecode" into masterfile
        put specialFolderPath("Documents") & "/WebScraper.livecode" into appfile
        put URL ("binfile:" & masterfile) into URL ("binfile:" & appfile)
      end if
      go stack specialFolderPath("Documents") & "/WebScraper.livecode"
      answer the filename of this stack
    end openStack
  14. Make sure that the Launch Scraper and Web Scraper apps are in the same folder. Open only the Launch Scraper app and make sure that the Web Scraper app is included in the Copy files of the Standalone Application Settings.
  15. Select your Test Target device and then Test. Note that the last answer statement will display the path and the filename where the main app is stored on your device. This can be commented out once you are comfortable that it is working.
  16. Use the Browser card to load a page with plenty of images, videos, or sounds on it and go to the Media card to see those listed.
  17. Select any item followed by a click on Done.
  18. If you like the image, sound, or video, use the Keep Media button to go to the end of the stack to save the media's URL.
  19. Choose more bits of media and keep them.
  20. Go to the Keepers section and use the Next and Prev buttons to browse through the items you've kept.
  21. The images should appear automatically and the video and audio can be started with the Play Media button.

What just happened?

We added the last feature of our application, a set of cards where we can go to view the bits of media that we've chosen to keep.

Have a go hero – add some preset locations

If you do make the Web Scraper app and start to find it useful, it's quite likely that there will be a set of web pages that you'd like to go back to again and again. To type the URL every time would be tedious. So, why not make a hidden field on the Browser card and type in a list of your favorite pages. Add a button to the card too, which will bring up a list of those pages for you to choose from. The one you choose can then load the Browser control at the desired page. All of the steps to do this were covered in the The Links card section.

It's pretty certain that if you've carefully followed all the steps in this chapter and indeed all the steps were perfect, you still wouldn't have an app ready to be submitted to the app stores! You would require a splash screen, a main menu, icons on the tab buttons as well and some love from a graphic designer! Feature wise, it would be nice if the images you keep could be zoomed and panned.

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

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