Adding a Flash resource type

Adding a Flash resource type

by Thomas Robb -
Number of replies: 3
I am attempting to add an additional resource type so that Flash files can be uploaded and used within Moodle, and to do it in such as way that the Flash file can transmit data to the Moodle database. Once established, I plan to use if for various language practice activties in which I want to be able to closely track the user's actions.

I have run up against a number of problems which could be solved in a number of ways, but would like some advice on the best "moodle-like" approach.

1) Time of data transmission

Moodle normally updates the database when the html page is being rewritten by php. In the case of Flash, this isn't feasible because multiple writes can occur while the user is using the module so the visible page must remain stable. This means that the data cannot be written directly by PHP, but rather by javascript on the page to a separate .php module which writes to the database while returning a "no content" header to the current HTML page. Agreed?

2) Talking to Moodle

The flash file cannot send data directly to the database, or even directly to an intermediate php file because some of the data that it requires -- the login data -- is possessed by the Moodle page. Therefore the flash movie either needs to send data to the embedding html page which contains hidden variables with the login data, *OR* the flash module could *read in* the login data from the HTML page so that it could communicate directly with the database. Does one of these methods make more sense than the other. (I know how to send the data out from Flash and have it forwarded on my Javascript. I haven't worked out the reverse procedure yet.

3) Location of .swf files

In order for the .swf file to 'talk' to moodle, it must be embedded in an HTML file using specific and tags in order to make it compatible with both MSIE and Netscape. These tags specify the source of the .swf module, but they cannot access the file if it is located in $CFG->dataroot directory since this is outside the path accessible by web browsers. It seems, therefore, that the moodle/files/index.php code (and/or moddlelib) needs to be able to create a separate directory within the "public_html" area, perhaps at the same level as the top-level "moodle" directory. Of course, if the user has made "moodle" the top level directory of the site, then there would be no choice, but to located it within the Moodle directory, but this would cause problems when Moodle is updated to a new version.

4) Creating the required directories

The current make_upload_directory function has hardwired in it that the base is the $CFG->moodledata directory. Thus either this code would need to be modifed to allow a separate base stipulation for a mdl_flash directory OR a separate but similar function would have to be written (not sound practice) OR the code could temporarily modify the value of the $CFG->moodledata directory, create the need directories, write the file and then restore $CFG->moodledata to its original value (tricky, workable, but dangerous).

I would appreciate any advice that people can give me on this!

Average of ratings: -
In reply to Thomas Robb

Re: Adding a Flash resource type

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Much of the rest of this is pretty much what the "program" resource is heading - providing a way for external programs to pass information back to Moodle. Note that Moodle can already pass data out to programs in the URL. I don't think there's a need for a separate Flash type here.

A possible method of providing this sort of 'return data' functionality would be to create a script that can accept URLs like:

return.php?id=x&type=log&userid=xx&info=xxxxxx
(for log entries - note the time etc is handled by Moodle)

return.php?id=x&type=grade&userid=xx&grade=34
(for grades)

As for data file location, I don't see the problem when using relative links for embedded files, same as for images. Have I missed something?

(I think we really need to look more closely at SCORM standards because this seems to be what they are all about and there may be no point re-inventing that particular Ferris wheel).
In reply to Martin Dougiamas

Re: Adding a Flash resource type

by Thomas Robb -
Perhaps I've missed something. If you place the data in the URL, then the page is going to change. I want the activity to remain visible and usable *AS* data is being sent to the server behind the scenes. Of course, if this "return.php" is being called but has the page header return "204 No Content" then this can be accomplished.

I have tried to use relative links without success. If the relative link pointed outside the highest level Moodle directory, but was still within the "Public_HTML" directory there was no problem, but the link could not see outside the public_html directory to content within the moodledata directory. This is as it should be, right? Files in the moodledata directory can be included on pages IF PHP is creating the page since it has the correct permissions to read from the external moodledata directory, but simple links on an HTML page (or in the embed block required to activate a Flash movie) cannot.

Is my thinking wrong here?

Okay, Martin, replied in a private message and striaghtened me out:


Sure it can. You can use relative links:

<img src="filename.jpg" >

or absolute links:

<img src="/file.php/2/filename.jpg">


I guess this is a matter of "a little knowledge being a dangerous thing" since it never occurred to me that it could be so simple!
In reply to Thomas Robb

Re: Adding a Flash resource type

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I'm pretty sure in Flash 5 that the movie can use getURL() to receive data back without the browser being involved - there should be no need for the page to change for the user. This is how Flash-based chat rooms work, for example.

My feeling is that the quick hack I described above might be good enough for most purposes, but to do this stuff properly I guess this might be useful: http://download.macromedia.com/pub/solutions/downloads/elearning/scorm_flashlo.pdf