具体的には,ステージ上を上下左右キーで操作できるキャラクタを作成し,配置する.
20110617.swf |
ダウンロード
※画面サイズは320x240,characterのサイズは,48x48とします.
(サンプルのサイズを変更しました)
20110617.swf |
// HTTP通信用、共通関数 function createXMLHttpRequest(cbFunc){ var XMLhttpObject = null; try{ XMLhttpObject = new XMLHttpRequest(); }catch(e){ try{ XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ try{ XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ return null; } } } if (XMLhttpObject) XMLhttpObject.onreadystatechange = cbFunc; return XMLhttpObject; } // document.getElementById function $(tagId){ return document.getElementById(tagId); }
<?php $db_user = "[user name]"; $db_password = "[password]"; $db_name = "new_schema"; $db_host = "10.5.1.240"; //create xml header('Content-type: text/xml; charset=utf-8'); echo '<?xml version="1.0"?><sa>'; $search_key = null; if(isset($_GET['search_key'])) { $search_key = $_GET['search_key']; $con = mysql_connect($db_host,$db_user,$db_password) or die("error!"); mysql_select_db($db_name,$con) or die("DB is not exist"); $strsql = "SET CHARACTER SET UTF8"; mysql_query($strsql,$con); $strsql = "SELECT id, name, score FROM [DB name] WHERE name LIKE '%".$search_key."%';"; $res = mysql_query($strsql,$con); while ($item = mysql_fetch_array($res)) { print "<list><id>".$item[0]."</id><name>".$item[1]."</name><score>".$item[2]."</score></list>"; } mysql_close($con); } echo '</sa>'; ?>
<html> <head> <meta http-equiv=content-type content="text/html; charset=UTF-8"> <title>real-time search sample(AJAX)</title> <STYLE TYPE="text/css"> <!-- .table1 { width: 400px; border-collapse: collapse; border: 1px #708090 solid; } .table1 TD { border: 1px #708090 solid; } --> </STYLE> <script type="text/javascript" src="xmlhttp.js"></script> <script type="text/javascript"> <!-- findText = findTextOld = ""; function loadXmlFile(fName){ httpObj = createXMLHttpRequest(displayData); if (httpObj){ httpObj.open("GET",fName,true); httpObj.send(null); } } function displayData(){ if ((httpObj.readyState == 4) && (httpObj.status == 200)){ xmlData = httpObj.responseXML; $("result").innerHTML = parseXmlData(httpObj.responseText); }else{ $("result").innerHTML = "Loading ..."; } } function parseXmlData(xmlData){ $("result").innerHTML = xmlData; idListTags = document.getElementsByTagName("id"); nameListTags = document.getElementsByTagName("name"); scoreListTags = document.getElementsByTagName("score"); idLen = idListTags.length; resultText = "<table class='table1'><tr><th colspan=4>list</th></tr><tr><td><b>id</b></td><td><b>name</b></td><td><b>score</b></td></tr>"; for(i=0; i<idLen; i++){ id = idListTags[i].childNodes[0].nodeValue; name = nameListTags[i].childNodes[0].nodeValue; score = scoreListTags[i].childNodes[0].nodeValue; str = name.match(findText); if (str){ resultText += "<tr><td>" + id + "</td><td><a href='http://10.5.1.240/~" + name + "' target='_blank'>" + name + "</a></td><td>" + score + "</td></tr>"; } } resultText += "</table>"; return resultText; } function inputCheck(){ findText = document.ajaxForm.requestText.value; if (findText != findTextOld) { str_search = "./backend.php?search_key=" + findText loadXmlFile(str_search); findTextOld = findText; }else{ // $("result").innerHTML = "Loading ..."; } setTimeout(" inputCheck()",500); // 0.5秒毎 } window.onload = inputCheck; // --> </script> </head> <body> <form name="ajaxForm" onSubmit="return false"> <input type="text" value="s" name="requestText"> </form> <div id="result"></div> </body> </html>
20110610.swf |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>user_list</title> </head> <body> <?php $db_user = "[USER NAME]"; $db_password = "[USER PASS]"; $db_name = "new_schema"; # $db_host = "localhost"; $db_host = "10.5.1.240"; $db = mysql_connect($db_host,$db_user,$db_password); mysql_select_db($db_name,$db); $str_sql = "select * from [DB NAME]"; $rs = mysql_query($str_sql,$db); $num = mysql_num_fields($rs); print("<table><tr><th colspan=3>USER LIST</th></tr>"); echo(" "); print("<tr>"); for ($i=0;$i<$num;$i++){ print("<td><b>".mysql_field_name($rs,$i)."</b></td>"); } print("</tr>"); while($row=mysql_fetch_array($rs)){ echo(" "); print("<tr>"); for($j=0;$j<$num;$j++){ print("<td>".$row[$j]."</td>"); } print("</tr>"); } print("</table>"); mysql_free_result($rs); mysql_close($db); ?> </body> </html>