Topic closed
archmage wrote:
Your mProjector program is useless. Flash can turn swfs to exe all by its self. Just open your flash file and create a projector (AKA exe file)
Also my fla (for flash CS3) is coming
Sorry to sound like a rep for the program, but that's not true. AS2 alone can't create standalones with transparent backgrounds, manipulate files (outside of flash.net.FileReference, which is useless), mess with the Registry, render web pages in a MovieClip, or a host of other things. I don't know why I'm defending it, other than the fact that I just think it's cool
!

Offline
archmage wrote:
To anyone that cares, here is the download link for my networking program
It needs 2 pcs running scratch to work
http://rapidshare.com/files/214987709/NetTest_CS3.fla.html
AWESOME!

Offline
archmage wrote:
To anyone that cares, here is the download link for my networking program
It needs 2 pcs running scratch to work
http://rapidshare.com/files/214987709/NetTest_CS3.fla.html
Only PCs (windows) not macs?
Offline
demosthenes wrote:
archmage wrote:
To anyone that cares, here is the download link for my networking program
It needs 2 pcs running scratch to work
http://rapidshare.com/files/214987709/NetTest_CS3.fla.htmlOnly PCs (windows) not macs?
Is it socket to socket do you have to make a direct connection to the other computer?
Offline
demosthenes wrote:
demosthenes wrote:
archmage wrote:
To anyone that cares, here is the download link for my networking program
It needs 2 pcs running scratch to work
http://rapidshare.com/files/214987709/NetTest_CS3.fla.htmlOnly PCs (windows) not macs?
Is it socket to socket do you have to make a direct connection to the other computer?
Macs can too. I ran it on my MacBook.
Offline
1. It works with any system that has flash cs3 or cs4
2. It directally connects to sockets
Offline
Goon94 wrote:
would simply using the swf version work as well?
Yes. I'll give you one.
Right here: http://rapidshare.com/files/215072358/NetTest_CS3.swf.html
Last edited by abeair (2009-03-29 16:07:48)
Offline
for some reason just .swf files won't work, I think it has to do with security
Just turn the file into an exe and it will work
Offline
archmage wrote:
for some reason just .swf files won't work, I think it has to do with security
Just turn the file into an exe and it will work
Archmage:
Nice job! I've been playing around a little with networking, and hope to have a general Adobe AIR application along the same lines done some time next week.
Offline
That is awesome chalkmarrow!
Too bad mine isn't working at the moment.
When you upload it I think you should also write instructions on how it works so that everyone can use it easily.
Offline
archmage wrote:
That is awesome chalkmarrow!
Too bad mine isn't working at the moment.
When you upload it I think you should also write instructions on how it works so that everyone can use it easily.
No problem. It's really easy to use. (A 9-year old was able to make a two-person Doodle program using it, which is a good test).
Though I don't have a lot of examples yet, I'll probably upload it early so you and others can come up with some good ideas for how to use it.
Offline
archmage wrote:
That is awesome chalkmarrow!
Too bad mine isn't working at the moment.
When you upload it I think you should also write instructions on how it works so that everyone can use it easily.
Here you go:
http://scratchconnections.wik.is/User:Chalkmarrow/Snyff
Maybe you can come up with something cool to do with it
Offline
I've put Chalkmarrow's original socket code into an AS3 class called ScratchSocket, which in addition to broadcasting and updating sensors, can interpret commands from Scratch. Right now the only two are 'getUrl' and 'nospace', and you can use them by:
1. Opening Flash CS3+ and loading the class description below into a blank .as file
2. Save the .as as ScratchSocket.as then make a new .fla in the same directory.
3. Place the following code into the .fla:
var socket:ScratchSocket=new ScratchSocket();
4. Save the .fla in the same directory as ScratchSocket.as
5. Open Scratch and enable sensor connections.
6. Test the .fla (ctrl+enter). It should trace ("connection successful")
7. Create a new global variable in Scratch called "sc.io.command"
8. Create this script in Scratch:
when flag clicked{
set sc.io.command to 0
wait 0.05 seconds
set sc.io.command to "getURL :: http://scratch.mit.edu :: sc.io.returnVoid
}Press the green flag. With any luck, your browser will open to the Scratch website!
Class code:
/*
ScratchSocket
@ This class sends and receives data from Scratch. Data received is sent to sc.Parse to
@ figure out what the heck Scratch wants, whereas other classes use this one to update
@ Scratch sensor variables.
@ Big thanks to Chalkmarrow for explaining how to communicate with Scratch with AS3
@ fullmoon, 2009
*/
package {
//Import everything we need to work with flash.net.Socket and handle its events
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.IOErrorEvent;
import flash.utils.ByteArray;
import flash.net.Socket;
import flash.net.navigateToURL;
import flash.net.URLRequest;
public dynamic class ScratchSocket {;
//Reserve space for socket, but don't declare it
private var socket:Socket;
public function ScratchSocket() {
//Declare socket
socket=new Socket ;
connect();
}
private function connect():void {
//Connect with Scratch on localhost, which responds to port 42001
socket.connect("localhost",42001);
socket.addEventListener(Event.CONNECT,socketConnect);
socket.addEventListener(Event.CLOSE,socketConnect);
socket.addEventListener(IOErrorEvent.IO_ERROR,socketConnect);
socket.addEventListener(ProgressEvent.SOCKET_DATA,dataIn);
}
public function update(sensor:String,value:String):void {
//Function to send a sensor update to Scratch
sendScratchMessage("sensor-update " + sensor + " " + value);
}
//Function to send a broadcast to Scratch
public function broadcast(broadcast:String):void {
trace("ScratchSocket.broadcast");
sendScratchMessage('broadcast "' + broadcast + '"');
}
private function sendScratchMessage(sendData:String):void {
//The Scratch Connections protocol requires every message sent to Scratch to
//be preceded by four bytes indicating the message length
var bytes:ByteArray=new ByteArray;
//Here are three '0' bytes
bytes[0]=0;
bytes[1]=0;
bytes[2]=0;
//Here's the actual message length
bytes[3]=sendData.length;
//Now we write the preceder plus the actual message to the socket
for (var i:Number=0; i < 4; i++) {
socket.writeByte(bytes[i]);
}
//Here comes the airplane!
socket.writeMultiByte(sendData,"us-ascii");
socket.flush();
}
private function socketConnect(Event):void {
//Handle connection events linked in constructor
switch (Event.type) {
case 'connect' :
trace("connection successful");
broadcast("jump");
break;
case 'close' :
trace("connection failed");
connect();
break;
case 'ioError' :
trace("connection failed through IOError");
break;
}
}
private function dataIn(event:ProgressEvent):void {
trace("ScratchSocket.dataIn");
//Create an empty string
var inString:String = "";
while (socket.bytesAvailable) {
//Read the next part of the socket data into inString
inString+=socket.readUTF();
}
//Send inString off to class SCparse for evaluation
evaluate(inString);
}
// Parse the data received from Scratch
private function evaluate(input:String) {
trace("ScratchSocket.evaluate("+input+")");
// Look for broadcast from Scratch
// Matches any string starting with 'broadcast ' followed by a string of non-return characters in "quotes"
var pattern1:RegExp = /broadcast\s\"(.*)"/;
var result:Object = pattern1.exec(input);
if (result != null) {
trace('Scratch broadcasted:'+result[1]);
}
// Look for sensor-update from Scratch
// Matches any sensor-update string Scratch sends
var pattern2:RegExp = /sensor-update\s\"Scratch-(.*)\"\s\"(.*)\"/;
result = pattern2.exec(input);
if (result != null) {
trace('Scratch changed variable '+result[1]+' to '+result[2]);
//If the variable changed is 'sc.io.command' then interpret it.
if (result[1]=="sc.io.command") {
interpret(result[2]);
}
}
}
private function interpret(input:String):void {
trace("ScatchSocket.interpret("+input+")");
var command:Array=input.split(" :: ");
trace(command);
var returnVal="";
//If the command returns to an invalid sensor then return to the default sensor, 'sc.io.defaultReturn'.
if (command[2].slice(0,6)!="sc.io.") {
command[2]="sc.io.defaultReturn";
}
//Find out what the command wants
switch (command[0]) {
case "getURL" :
trace("sc.getURL");
navigateToURL(new URLRequest(command[1]));
returnVal="success";
update(command[2],returnVal);
break;
case "nospace" :
trace("sc.concat");
var a:Array=command[1].split(" ");
for (var i=0; i<a.length; i++) {
if (a[i]=="") {
a[i]=" ";
}
}
var s:String=a.join("");
returnVal=s;
update(command[2],returnVal);
}
}
}
}This is just a test, and eventually I plan to incorporate getter/setter functions for Flash persistent Shared Objects and advanced keyboard/mouse input, etc into an AIR application like Snyff. But for now, I'm having trouble getting Scratch to receive a message with spaces in it. When I try the command:
set sc.io.command to "nospace :: t h i s i s c o o l :: sc.io.sayThis" say(sensor value(sc.io.sayThis))
which is supposed to take a concatenated list from Scratch and turn it into an actual word, it just returns "this", which leads me to my question: Can Scratch receive messages with spaces in them?
Last edited by fullmoon (2009-04-06 13:14:53)

Offline
That's a great idea, converting it to an AS3 class. Looks really cool. Regarding your question, I don't believe Scratch has any problems receiving spaces in messages, since I do that with Snyff all the time. I haven't looked at your program closely, so I'm not sure yet what the issue is. Good luck with this, though.
Offline
Topic closed