[system] / trunk / pg / macros / AppletObjects.pl Repository:
ViewVC logotype

View of /trunk/pg/macros/AppletObjects.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5582 - (download) (as text) (annotate)
Tue Nov 6 16:45:28 2007 UTC (11 years, 10 months ago) by gage
File size: 5513 byte(s)
Provides front end for Applet.pm.

To use applets  add loadMacros("AppletObjects.pl")
to the top of your PG problem file.

$applet = FlashApplet();

gets you started.  There is reasonable POD documentation in this file including a working problem
for the ExternalInterface.swf  flash object.

-- Mike

    1 ################################################################################
    2 # WeBWorK Online Homework Delivery System
    3 # Copyright  2000-2007 The WeBWorK Project, http://openwebwork.sf.net/
    4 # $CVSHeader: pg/macros/MathObjects.pl,v 1.8 2007/10/25 17:11:59 sh002i Exp $
    5 #
    6 # This program is free software; you can redistribute it and/or modify it under
    7 # the terms of either: (a) the GNU General Public License as published by the
    8 # Free Software Foundation; either version 2, or (at your option) any later
    9 # version, or (b) the "Artistic License" which comes with this package.
   10 #
   11 # This program is distributed in the hope that it will be useful, but WITHOUT
   12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   13 # FOR A PARTICULAR PURPOSE.  See either the GNU General Public License or the
   14 # Artistic License for more details.
   15 ################################################################################
   16 
   17 =head1 NAME
   18 
   19 AppletOjects.pl - Macro-based front end for the Applet.pm module.
   20 
   21 
   22 =head1 DESCRIPTION
   23 
   24 This subroutines in this
   25 file provide mechanisms to insert Flash applets (and later Java applets)
   26 into a WeBWorK problem.
   27 
   28 
   29 =head1 SEE ALSO
   30 
   31 L<Applets.pm>.
   32 
   33 =cut
   34 
   35 sub _PGapplets_init {}; # don't reload this file
   36 
   37 =head3
   38   FlashApplet
   39 
   40   Useage:    $applet = FlashApplet();
   41 
   42 =cut
   43 
   44 sub FlashApplet {
   45   return new FlashApplet();
   46 
   47 }
   48 
   49 package FlashApplet;
   50 
   51 =head2 Methods
   52 
   53 =cut
   54 
   55 ## this method is defined in this file
   56 ## because the main subroutines HEADER_TEXT and MODES are
   57 ## not available to the module FlashApplet when that file
   58 ## is compiled (at the time the apache child process is first initialized)
   59 
   60 =head3  insert
   61 
   62   Useage:   TEXT( $applet->insert() );
   63             \{ $applet->insert \}     (used within BEGIN_TEXT/END_TEXT blocks)
   64 
   65 =cut
   66 
   67 =pod
   68 
   69 Inserts applet at this point in the HTML code.  (In TeX mode a message "Applet" is written.)  This method
   70 also adds the applets header material into the header portion of the HTML page. It effectively inserts
   71 the outputs of both C<$applet-E<gt>inserHeader> and C<$applet-E<gt>insertObject> (defined in L<Applet.pm> ) in the appropriate places.
   72 
   73 =cut
   74 
   75 sub insert {  ## inserts both header text and object text
   76   my $self = shift;
   77   main::HEADER_TEXT($self->insertHeader());
   78     return main::MODES(TeX=>' {\bf flash applet } ', HTML=>$self->insertObject);
   79 }
   80 
   81 
   82 =head3 Example problem
   83 
   84 
   85 =cut
   86 
   87 
   88 
   89 =pod
   90 
   91 
   92   DOCUMENT();
   93 
   94   # Load whatever macros you need for the problem
   95   loadMacros("PG.pl",
   96          "PGbasicmacros.pl",
   97          "PGchoicemacros.pl",
   98          "PGanswermacros.pl",
   99          "AppletObjects.pl",
  100          "MathObjects.pl",
  101          "source.pl"
  102         );
  103 
  104   ## Do NOT show partial correct answers
  105   $showPartialCorrectAnswers = 0;
  106 
  107 
  108 
  109   ###################################
  110   # Create  link to applet
  111   ###################################
  112 
  113   $applet = FlashApplet();
  114   my $appletName = "ExternalInterface";
  115   $applet->codebase(findAppletCodebase("$appletName.swf"));
  116   $applet->appletName($appletName);
  117   $applet->appletId($appletName);
  118 
  119   # findAppletCodebase looks for the applet in a list
  120   # of locations specified in global.conf
  121 
  122   ###################################
  123   # Add java script functions to header section of HTML to
  124   # communicate with the applet.
  125   ###################################
  126 
  127   $applet->header(<<'END_HEADER');
  128   <script type="text/javascript" src="https://devel.webwork.rochester.edu:8002/webwork2_files/js/BrowserSniffer.js">
  129   </script>
  130 
  131 
  132   <script language="JavaScript">
  133     function getBrowser() {
  134         //alert("look for sniffer");
  135       var sniffer = new BrowserSniffer();
  136       //alert("found sniffer" +sniffer);
  137       return sniffer;
  138     }
  139 
  140     function updateStatus(sMessage) {
  141       //alert("update form with " + sMessage);
  142       //window.document.problemMainForm.playbackStatus.value = sMessage;
  143       //document.problemMainForm.playbackStatus.value = sMessage;
  144         document.getElementById("playbackStatus").value = sMessage;
  145     }
  146 
  147     function newColor() {
  148       //var app = getFlashMovie("ExternalInterface").getElementById("movie1");
  149       // alert(app);
  150       // The difficult issue in adapting Barbara's original file was locating
  151       // the object.  It took several tries to find a method that worked
  152       // and it is quite likely that it will not work in all browsers.
  153 
  154       //alert("update color");
  155       //alert(getFlashMovie("ExternalInterface"));
  156       getFlashMovie("ExternalInterface").updateColor(Math.round(Math.random() * 0xFFFFFF));
  157     }
  158 
  159     function submitAction() { newColor()
  160     }
  161 
  162   </script>
  163   END_HEADER
  164 
  165   ###################################
  166   # Configure applet
  167   ###################################
  168 
  169   # not used here.  Allows for uploading an xml string for the applet
  170 
  171 
  172 
  173 
  174   ###################################
  175   # write the text for the problem
  176   ###################################
  177 
  178   TEXT(beginproblem());
  179 
  180 
  181   TEXT( MODES(TeX=>'object code', HTML=><<END_SCRIPT ) );
  182   <script>
  183       //alert("foobar");
  184     initialize();
  185     // this should really be done in the <body> tag -- can we make that happen?
  186   </script>
  187   END_SCRIPT
  188 
  189 
  190   BEGIN_TEXT
  191   \{ $applet->insert \}
  192     $PAR
  193 
  194     The Flash object operates above this line.  The box and button below this line are part of
  195     the WeBWorK problem.  They communicate with the Flash object.
  196     $HR
  197     Status <input type="text" id="playbackStatus" value="started" /><br />
  198     Color <input type="button" value="new color" name="newColorButton" onClick="newColor()" />
  199      $PAR $HR
  200      This flash applet was created by Barbara Kaskosz.
  201 
  202   END_TEXT
  203 
  204   ENDDOCUMENT();
  205 
  206 
  207 
  208 
  209 =cut

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9