Differences
This shows you the differences between two versions of the page.
| Previous revision | |||
| — | helloeeg_adobe_flash_tutorial [2026/08/13 08:17] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Hello EEG! Tutorial for Adobe Flash ====== | ||
| + | ====== Features ====== | ||
| + | * Create an Adobe Flash project | ||
| + | * Connect to the ThinkGear Connector using Adobe ActionScript 3 in Adobe Flash | ||
| + | * Retrieve and use eSense from the MindSet | ||
| + | ====== Required Materials | ||
| + | This tutorial requires the following materials: | ||
| + | * [[http:// | ||
| + | * [[thinkgear_connector_tgc|ThinkGear Connector]] | ||
| + | * Adobe Flash CS4 Professional | ||
| + | * as3corelib | ||
| + | * {{: | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ====== Recommended Reading ====== | ||
| + | * {{: | ||
| + | * {{: | ||
| + | * as3corelib API Documentation (JSON class only) (found in as3corelib download) | ||
| + | ====== Prerequisite Steps ====== | ||
| + | * Install Adobe Flash CS4 Professional | ||
| + | * Install the Bluetooth adapter software and hardware included with your MindSet | ||
| + | * Install ThinkGear Connector | ||
| + | * Download and extract as3corelib | ||
| + | * Pair the MindSet with computer | ||
| + | < | ||
| + | |||
| + | ====== Create a new Flash project ====== | ||
| + | - Open Adobe Flash | ||
| + | - In the upper right corner, select the // | ||
| + | - Add '' | ||
| + | - Edit >> Preferences (or Flash >> Preferences on Mac) and select ActionScript catagory | ||
| + | - Click on // | ||
| + | - Click on //Browse To Path// button in the Library path section | ||
| + | - Browse to the folder that contains the // | ||
| + | - Create a new Flash project in the Project inspector\\ {{: | ||
| + | - Type in the project name " | ||
| + | - Select a folder to save your project | ||
| + | - Select // | ||
| + | - Create a Flash file in the project panel\\ {{: | ||
| + | - Select //Flash File// as the file type | ||
| + | - Use " | ||
| + | - Check //Open file after creation// and click //Create File// | ||
| + | - In the Project inspector, right click on " | ||
| + | - Create a Class file in the project panel\\ {{: | ||
| + | - Type in " | ||
| + | - Double-click on " | ||
| + | - In the Properties inspector, type in " | ||
| + | ====== Connecting to ThinkGear Connector ====== | ||
| + | Double-click on the DisplayWindow.as file in the Project panel. | ||
| + | < | ||
| + | package | ||
| + | public class DisplayWindow { | ||
| + | |||
| + | // Constants: | ||
| + | // Public Properties: | ||
| + | // Private Properties: | ||
| + | |||
| + | // Initialization: | ||
| + | public function DisplayWindow() { | ||
| + | } | ||
| + | |||
| + | // Public Methods: | ||
| + | // Protected Methods: | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | Add the following packages to the '' | ||
| + | < | ||
| + | package | ||
| + | import flash.display.*; | ||
| + | import flash.events.*; | ||
| + | import flash.net.Socket; | ||
| + | import com.adobe.serialization.json.* | ||
| + | |||
| + | public class DisplayWindow { | ||
| + | </ | ||
| + | Since the '' | ||
| + | < | ||
| + | public class DisplayWindow extends Sprite { | ||
| + | </ | ||
| + | Declare the following variables to store information coming from the MindSet | ||
| + | < | ||
| + | // Public Properties: | ||
| + | public var attention: | ||
| + | public var meditation: | ||
| + | public var poorSignal: | ||
| + | </ | ||
| + | '' | ||
| + | < | ||
| + | // Private Properties: | ||
| + | private var thinkGearSocket : Socket; | ||
| + | </ | ||
| + | The '' | ||
| + | < | ||
| + | package | ||
| + | import flash.display.*; | ||
| + | import flash.events.*; | ||
| + | import flash.net.Socket; | ||
| + | import com.adobe.serialization.json.JSON; | ||
| + | |||
| + | public class DisplayWindow extends Sprite { | ||
| + | |||
| + | // Constants: | ||
| + | // Public Properties: | ||
| + | public var attention: | ||
| + | public var meditation: | ||
| + | public var poorSignal: | ||
| + | // Private Properties: | ||
| + | private var thinkGearSocket : Socket; | ||
| + | |||
| + | // Initialization: | ||
| + | public function DisplayWindow() { | ||
| + | } | ||
| + | // Public Methods: | ||
| + | // Protected Methods: | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | Save // | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Use the Text Tool to create a text field in the middle of the stage. Type in " | ||
| + | |||
| + | {{: | ||
| + | |||
| + | In the Properties inspector, select //Dynamic Text// and enter in " | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Save // | ||
| + | < | ||
| + | public function DisplayWindow() { | ||
| + | thinkGearSocket = new Socket(); | ||
| + | thinkGearSocket.addEventListener(ProgressEvent.SOCKET_DATA, | ||
| + | } | ||
| + | </ | ||
| + | '' | ||
| + | Next, open the socket connection by calling the connect function. | ||
| + | < | ||
| + | thinkGearSocket.connect(" | ||
| + | </ | ||
| + | By default, the ThinkGear Connector sends data in a binary packet format. | ||
| + | < | ||
| + | var configuration : Object = new Object(); | ||
| + | configuration[" | ||
| + | configuration[" | ||
| + | thinkGearSocket.writeUTFBytes(JSON.encode(configuration)); | ||
| + | </ | ||
| + | Your DisplayWindow() function should now look like this: | ||
| + | < | ||
| + | public function DisplayWindow() { | ||
| + | |||
| + | thinkGearSocket = new Socket(); | ||
| + | thinkGearSocket.addEventListener(ProgressEvent.SOCKET_DATA, | ||
| + | thinkGearSocket.connect(" | ||
| + | | ||
| + | var configuration : Object = new Object(); | ||
| + | configuration[" | ||
| + | configuration[" | ||
| + | thinkGearSocket.writeUTFBytes(JSON.encode(configuration)); | ||
| + | } | ||
| + | </ | ||
| + | Note that the event listener added has '' | ||
| + | < | ||
| + | public function DisplayWindow() { | ||
| + | ... | ||
| + | } | ||
| + | |||
| + | // Protected Methods: | ||
| + | private function dataHandler(e : ProgressEvent){ | ||
| + | } | ||
| + | </ | ||
| + | When the application is connected to the ThinkGear Connector, this function will retrieve and handle all data from the MindSet. | ||
| + | |||
| + | First, read the packet into memory. | ||
| + | < | ||
| + | var packetString : String = thinkGearSocket.readUTFBytes(thinkGearSocket.bytesAvailable); | ||
| + | thinkGearSocket.flush(); | ||
| + | </ | ||
| + | The ThinkGear Connector will send JSON objects delimited by a carriage return character (\r). The packet string can be split up by using the '' | ||
| + | < | ||
| + | var packets : Array = packetString.split(/ | ||
| + | </ | ||
| + | Now iterate through the '' | ||
| + | < | ||
| + | var data: | ||
| + | for each (var packet: | ||
| + | if(packet != "" | ||
| + | try { | ||
| + | data = JSON.decode(packet); | ||
| + | } catch (jError: | ||
| + | //do error handling here | ||
| + | } | ||
| + | if(data[" | ||
| + | poorSignal = data[" | ||
| + | if(poorSignal == 0) { | ||
| + | attention = data[" | ||
| + | meditation = data[" | ||
| + | trace(attention); | ||
| + | } | ||
| + | else { | ||
| + | if(poorSignal == 200) { | ||
| + | attention = 0; | ||
| + | meditation = 0; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | data = null; | ||
| + | } | ||
| + | </ | ||
| + | With valid data, update the text label with eSense data | ||
| + | < | ||
| + | label1.text = " | ||
| + | </ | ||
| + | Your '' | ||
| + | < | ||
| + | private function dataHandler(e : ProgressEvent){ | ||
| + | |||
| + | var packetString : String = thinkGearSocket.readUTFBytes(thinkGearSocket.bytesAvailable); | ||
| + | thinkGearSocket.flush(); | ||
| + | |||
| + | var packets : Array = packetString.split(/ | ||
| + | var data: | ||
| + | for each (var packet: | ||
| + | if(packet != "" | ||
| + | try { | ||
| + | data = JSON.decode(packet); | ||
| + | //decode the data to an array | ||
| + | } catch (jError: | ||
| + | //do error handling here | ||
| + | } | ||
| + | if(data[" | ||
| + | poorSignal = data[" | ||
| + | if(poorSignal == 0) { | ||
| + | attention = data[" | ||
| + | meditation = data[" | ||
| + | trace(attention); | ||
| + | } | ||
| + | else { | ||
| + | if(poorSignal == 200) { | ||
| + | attention = 0; | ||
| + | meditation = 0; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | data = null; | ||
| + | label1.text = " | ||
| + | + " | ||
| + | } /*for each*/ | ||
| + | } /*function dataHandler*/ | ||
| + | </ | ||
| + | |||
| + | Save // | ||
| + | {{: | ||
| + | |||
| + | ====== Appendix ====== | ||
| + | ===== Running a local SWF file ===== | ||
| + | In order to run the HelloEEG SWF file locally, you must change Adobe Flash' | ||