Hi Gaël,
Thanks for your interest in the SWF Activity Module. It doesn't currently allow user data to be passed between the
server and client. I think that this is generally a bad idea for security reasons.
I handle all the user data on the server with Flash Remoting so that no sensitive information will ever be passed back and forth over the WWW:
http://docs.moodle.org/en/Development:AMF3This allows Flash clients to communicate directly with Moodle's back end and do just about anything you like. Something like retrieving user data would be very easy and there are some examples included on the
Moodle docs page on the link above. I designed the SWF Activity Module with both Flash Remoting and
XML in mind so if you intend to do a lot of database driven work with Flash it's an ideal way to get started.
On the other hand,
If all you want to do is have the user's name appear in your Flash app., then you can customise the moodle/mod/swf/lib.php page to pass that data in as FlashVars. It's only a few lines of code that you need to add. Remember to make the changes in the code in both the swf_print_header_js() and swf_print_body() functions.
I've highlighted the modified code.
I hope this answers your questions. Don't hesitate to contact me if you have any further questions. I'm always looking for ways to improve the module.
Good luck,
Matt
/*** Construct Javascript SWFObject embed code for <head> section of view.php* Note: '?'.time() is used to prevent browser caching for XML and SWF files.** @param $swf (mdl_swf DB record for current SWF module instance)* @return string*/function swf_print_header_js($swf) { global $CFG; global $COURSE; global $USER; // add the USER object which contains username
$swf->username = $USER->username; // add username variable to swf object, it then gets passed in in the JavaScript code below and in the object and embed tags in the swf_print_body() function
// Build URL to moodledata directory // This is where SWF files and media should be stored $swf_moodledata = $CFG->wwwroot.'/file.php/'.$COURSE->id.'/'; $swf_coursepage = $CFG->wwwroot.'/course/view.php?id='.$COURSE->id; // Build Javascript code for view.php print_header() function $swf_header_js = '<script type="text/javascript" src="swfobject/swfobject.js"></script> <script type="text/javascript"> var flashvars = {}; flashvars.gateway = "'.$CFG->wwwroot.'/lib/amfphp/gateway.php"; flashvars.swfid = "'.$swf->id.'"; flashvars.instance = "'.$swf->moduleid.'"; flashvars.interaction = "'.$swf->interaction.'"; flashvars.moodledata = "'.$swf_moodledata.'"; flashvars.coursepage = "'.$swf_coursepage.'"; flashvars.xmlurl = "'.$swf_moodledata.$swf->xmlurl.'?'.time().'"; flashvars.apikey = "'.$swf->apikey.'"; flashvars.flashvar1 = "'.$swf->flashvar1.'"; flashvars.flashvar2 = "'.$swf->flashvar2.'"; flashvars.flashvar3 = "'.$swf->flashvar3.'"; flashvars.username = "'.$swf->username.'"; var params = {}; params.play = "'.$swf->width.'"; params.loop = "'.$swf->loop.'"; params.menu = "'.$swf->menu.'"; params.quality = "'.$swf->quality.'"; params.scale = "'.$swf->scale.'"; params.salign = "'.$swf->salign.'"; params.wmode = "'.$swf->wmode.'"; params.bgcolor = "#'.$swf->bgcolor.'"; params.devicefont = "'.$swf->devicefont.'"; params.seamlesstabbing = "'.$swf->seamlesstabbing.'"; params.allowfullscreen = "'.$swf->allowfullscreen.'"; params.allowscriptaccess = "'.$swf->allowscriptaccess.'"; params.allownetworking = "'.$swf->allownetworking.'"; var attributes = {}; attributes.id = "contentid"; attributes.align = "middle"; swfobject.embedSWF("'.$swf_moodledata.$swf->swfurl.'?'.time().'", "myAlternativeContent", "'.$swf->width.'", "'.$swf->height.'", "'.$swf->version.'", "swfobject/expressInstall.swf", flashvars, params, attributes); </script>'; return $swf_header_js;}/*** Construct Javascript SWFObject embed code for <body> section of view.php* Note: everything between the <div id="myAlternativeContent"></div> tags* is overwritten by SWFObject. This embed code will only be used if SWFObject* fails for some reason, e.g. Javascript isn't enabled. In any case, the module* should function normally.** @param $swf (mdl_swf DB record for current SWF module instance)* @param $cm module instance data* @return string*/function swf_print_body($swf) { global $CFG; global $COURSE; global $USER; $swf->username = $USER->username; // Build URL to moodledata directory $swf_moodledata = $CFG->wwwroot.'/file.php/'.$COURSE->id.'/'; $swf_coursepage = $CFG->wwwroot.'/course/view.php?id='.$COURSE->id; // prevent using SWF file in browser cache by attaching time as query string $swf_swfurl = $swf_moodledata.$swf->swfurl.'?'.time(); $swf_xmlurl = $swf_moodledata.$swf->xmlurl.'?'.time(); // e.g. http://yourmoodlesite.com/file.php/99/swf/flash_file.swf?123513670 // Build URL to AMFPHP gateway for Flash Remoting $swf_gateway = $CFG->wwwroot.'/lib/amfphp/gateway.php'; // e.g. http://yourmoodlesite.com/lib/amfphp/gateway.php //instance = "'.$cm->id.' $swf_body = '<div align="center"> <div id="myAlternativeContent"> <div> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'.$swf->width.'" height="'.$swf->height.'" id="contentid" align="'.$swf->align.'"> <param name="movie" value="'.$swf_swfurl.'" /> <param name="play" value="'.$swf->play.'" /> <param name="loop" value="'.$swf->loopswf.'" /> <param name="menu" value="'.$swf->menu.'" /> <param name="quality" value="'.$swf->quality.'" /> <param name="scale" value="'.$swf->scale.'" /> <param name="salign" value="'.$swf->salign.'" /> <param name="wmode" value="'.$swf->wmode.'" /> <param name="bgcolor" value="#'.$swf->bgcolor.'" /> <param name="devicefont" value="'.$swf->devicefont.'" /> <param name="seamlesstabbing" value="'.$swf->seamlesstabbing.'" /> <param name="allowfullscreen" value="'.$swf->allowfullscreen.'" /> <param name="allowscriptaccess" value="'.$swf->allowscriptaccess.'" /> <param name="allownetworking" value="'.$swf->allownetworking.'" /> <param name="flashvars" value="gateway='.$swf_gateway.'&swfid='.$swf->id.'&interaction='.$swf->interaction.'&instance='.$swf->moduleid.'&moodledata='.$swf_moodledata.'&coursepage='.$swf_coursepage.'&swfurl='.$swf_swfurl.'&xmlurl='.$swf_xmlurl.'&apikey='.$swf->apikey.'&flashvar1='.$swf->flashvar1.'&flashvar2='.$swf->flashvar2.'&flashvar3='.$swf->flashvar3.'&username='.$swf->username.'" /> <!--[if !IE]>--> <object type="application/x-shockwave-flash" data="'.$swf_swfurl.'" width="'.$swf->width.'" height="'.$swf->height.'" align="'.$swf->align.'"> <param name="play" value="'.$swf->play.'" /> <param name="loop" value="'.$swf->loop.'" /> <param name="menu" value="'.$swf->menu.'" /> <param name="quality" value="'.$swf->quality.'" /> <param name="scale" value="'.$swf->scale.'" /> <param name="salign" value="'.$swf->salign.'" /> <param name="wmode" value="'.$swf->wmode.'" /> <param name="bgcolor" value="#'.$swf->bgcolor.'" /> <param name="devicefont" value="'.$swf->devicefont.'" /> <param name="seamlesstabbing" value="'.$swf->seamlesstabbing.'" /> <param name="allowfullscreen" value="'.$swf->allowfullscreen.'" /> <param name="allowscriptaccess" value="'.$swf->allowscriptaccess.'" /> <param name="allownetworking" value="'.$swf->allownetworking.'" /> <param name="flashvars" value="gateway='.$swf_gateway.'&swfid='.$swf->id.'&interaction='.$swf->interaction.'&instance='.$swf->moduleid.'&moodledata='.$swf_moodledata.'&coursepage='.$swf_coursepage.'&swfurl='.$swf_swfurl.'&xmlurl='.$swf_xmlurl.'&apikey='.$swf->apikey.'&flashvar1='.$swf->flashvar1.'&flashvar2='.$swf->flashvar2.'&flashvar3='.$swf->flashvar3.'&username='.$swf->username.'" /> <!--<![endif]-->'.get_string('embederror','swf').'<div align="center"> <p><strong>This activity requires <a href="http://www.adobe.com/products/flashplayer/">Flash Player '.$swf->version.'</a> to be installed.</strong></p> <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" border=0/> </a> </p></div> <!--[if !IE]>--> </object> <!--<![endif]--> </object> </div> </div>'; return $swf_body;}