I have a simple example chat demo use Flash like:
The index.html:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
LIGHTSTREAMER - www.lightstreamer.com
Flash Bridge Stock-List Demo
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Lightstreamer :: Flash Bridge :: Chat Demo</title>
<link rel="stylesheet" type="text/css" href="css/chat.css" />
<!-- load Lightstreamer libraries -->
<script src="../commons/lightstreamer/lscommons.js" type="text/javascript"></script>
<script src="../commons/lightstreamer/lspushpage.js" type="text/javascript"></script>
<!-- load Lightstreamer Flash Bridge -->
<script src="bridge/lsflashbridge.js" type="text/javascript"></script>
<!-- load some code, shared among most of these demo applications, used for
creating or seeking the Master Push-Page and the Engine.
Please study carefully the source code of misc.js to learn how it works
and to change it at your convenience -->
<script src="../commons/custom/misc.js" type="text/javascript"></script>
</head>
<body>
<!-- Flash object -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="400" height="300" id="flashObject" style="margin-left: 12px;">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="demoFlashChat.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="demoFlashChat.swf" quality="high" bgcolor="#ffffff" width="400" height="300" name="flashObject" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
<!-- message submission form -->
<form onSubmit="submitForm(); return false;" class="formPanel">
<div class="sendTitle">Send a message:</div>
<div class="formElements">
<input id="user_message" type="text" size="70" />
<input id="mex_button" type="submit" value="Send" />
</div>
</form>
<!-- JavaScript code specific of this application -->
<script type="text/javascript">
function submitForm() {
var textField = document.getElementById("user_message");
if (window.engineRef && textField) {
var text = textField.value;
textField.value = "";
if (!text) {
alert("Can't send an empty message");
} else {
var mex = "CHAT|" + text;
engineRef.sendMessage(mex, "Chats", null, 5000);
}
}
}
//////////////// JavaScript code that extends some functions defined in misc.js
// remember the current engine reference, if any
var engineRef = null;
// define an extension to the onEngineReady callback defined in misc.js
function onEngineReady(lsEngine) {
// store the engine reference
engineRef = lsEngine;
}
// define an extension to the onEngineLost callback defined in misc.js
function onEngineLost() {
engineRef = null;
}
// these two functions are defined in misc.js
var pushPage = initializeDemoPushPage("../commons/custom/", true, onEngineReady, onEngineLost);
initializeDemoEngine(pushPage, "../commons/lightstreamer/", null);
//////////////// Flash Bridge Configuration
var flashHandler = new FlashBridge("flashObject");
</script>
</body>
</html>
And the demoFlashChat.fla with 2 input text: text1 and statusField,with as code like:
Code:
import flash.external.ExternalInterface;
#include "..\lib\lsjavascriptbridge.as"
_root.text1.text = "";
_root.statusField.text = "WAITING";
function bridgeIsReady() {
_root.statusField.text = "Bridge ready";
}
function statusChange(newStatus) {
_root.statusField.text = newStatus;
}
function myOnStart() {
_root.text1.text = "";
}
function myOnItemUpdate(itemPos,itemObj,itemName) {
if (itemPos == 1) {
if (itemObj.isValueChanged(1) == true) {
_root.text1.text = itemObj.getNewValue(1);
}
}
}
var bridge = new JavaScriptBridge("flashObject");
bridge.onReady = bridgeIsReady;
bridge.onStatusChange = statusChange;
var myTable = new FlashTable("chat_room", null, "DISTINCT");
myTable.setDataAdapter("CHAT_ROOM");
myTable.setSnapshotRequired(true);
myTable.onItemUpdate = myOnItemUpdate;
myTable.onStart = myOnStart;
bridge.addTable(myTable,"FlashTable1");
bridge.bind();
2 above code file are combined from 2 your demo: ChatDemo and Flash_StockListDemo_Basic. But it can't run.I don't know. The problem maybe in callback function: myOnItemUpdate,because when I try put a code line as:_root.text1.text = "test" in this function(I'm so sorry, because now I only know debug like that in Flash), it don't display, but in your example(Flash_StockListDemo_Basic), a same line will display.
The above example only make a simple work: when user type a text line on HTML form, it transmit to LS server, then back to text1 variable in Flash, and display.
Thanks for your help!
Bookmarks