mouse movment recorder - send array to database using php and sql and back

flashdave
flashdave used Ask the Experts™
on
I want to be able to record peoples mouse movements in flash , be able to save them to a database and also be able to load others.  Any help appreciated.
mouseMC._visible = false;
 
var recording = false;
var playing = false;
var index = 0;
 
var mPosX = new Array();
var mPosY = new Array();
 
_root.onEnterFrame = function()
{
	if(recording)
	{
		mPosX[index] = _root._xmouse;  // send to database
		mPosY[index] = _root._ymouse;    // send to database
		
		index++
	}
	else if (playing)
	{
		mouseMC._x = mPosX[index]  //load from database
		mouseMC._y = mPosY[index]  //load from database
		
		
		index++;
		if(index == mPosX.length)
		{
			Mouse.show();
			_root.mouseMC._visible = false;
		}
	}
}
 
recBtn.onRelease = function()
{
	Mouse.show();
	
	_root.mouseMC._visible = false;
	
	_root.recording = true;
	_root.playing = false;
	_root.index = 0;	
	
	_root.mPosX = new Array();
	_root.mPosY = new Array();
 
}
playBtn.onRelease = function()
{
	Mouse.hide();
	
	_root.mouseMC._visible = true;
	
	_root.recording = false;
	_root.playing = true;
	_root.index = 0;
}
stopBtn.onRelease = function()
{
	Mouse.show();
	
	_root.mouseMC._visible = false;
	
	_root.recording = false;
	_root.playing = false;
	_root.index = 0;
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Richard QuadlingSenior Software Developer

Commented:
It seems you've got the Flash side sorted. What help are you looking for? What have you got at the moment?

Author

Commented:
I've been able to send a variable from flash to an sql table. I guess this is a start.

How could I send a whole array to a database with each value of the array put against an auto increment which I could then load later. I need help with the split command in flash and how to send an whole array.


I would ideally like to have different users in different tables and be able to load and save the sessions. I'm just going to take this one step at a time. Any help with coding would be appreciated.
<?php
$xvalue = $_POST["xvalue"];
   $host = 'localhost';
   $dbuser = 'root';
   $dbpass = 'root';
   $dbname = 'ok';
   $table = 'mouse';
   $db = @mysql_connect($host,$dbuser,$dbpass) or die("error=could not connect to $host");
   $db = mysql_select_db($dbname);
   if(!$db)
   {
      print "error=could not connect to $dbname table";
      exit;
   }
   $xvalue = $_POST["xvalue"];
   $xvalue = trim($xvalue);
   $query = @mysql_query("INSERT INTO $table (xvalue) VALUES "."('$xvalue')");
?>
 
//actionscript
 
on (release) {
	var regVars:LoadVars = new LoadVars();
 
	regVars.xvalue = 7;
	regVars.sendAndLoad("http://localhost:8888/store.php", regVars, "POST");
	btnSubmitForm.enabled = false;
	regVars.onLoad = function() {
		tWhatDoesItDo.text = "success";
	};
}

Open in new window

Senior Software Developer
Commented:
I don't know Flash (it looks a lot like JavaScript).

But http://livedocs.adobe.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=00001203.html deals with converting an array to a string, though http://livedocs.adobe.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=00001203.html may be better.

I would guess something like this ...

var s_Changes = 'x[]=' + mPosX.join('&x[]=') + '&y[]=' + mPosY.join('&y[]=');

Maybe.

Then in PHP ...

$_POST['x'] and $_POST['y'] would be available.
Richard QuadlingSenior Software Developer

Commented:
What did you have to do to get this working?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial