This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#76 2009-02-20 13:41:14

golfer3
Scratcher
Registered: 2008-11-02
Posts: 1000+

Re: scratch networking commands with actionscript 2.0

btw, archmage how do u get it so in your sig that it has the name of your game??

Offline

 

#77 2009-02-20 13:42:36

golfer3
Scratcher
Registered: 2008-11-02
Posts: 1000+

Re: scratch networking commands with actionscript 2.0

☻☻☻☻☻☺☻☻☻☻☻☺☻☻☻☻☻Red text

Offline

 

#78 2009-02-20 13:43:42

golfer3
Scratcher
Registered: 2008-11-02
Posts: 1000+

Re: scratch networking commands with actionscript 2.0

hello people i am happy  smile

Offline

 

#79 2009-02-20 14:49:54

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: scratch networking commands with actionscript 2.0

archmage wrote:

Magnie wrote:

So How Close Are You Done With This and SSBS? (Super Smash Brothers Scratch)

Not that close at all. Still fixing the character attacks. Right now I am working on the scratch networking features. I've had a lot of school work lately so that is slowing me down.

Ok.  smile  Something To Help You:
[blocks]
<set{ Homework }to( 99% Done )
[/blocks]
Golfer3, Do Not Spam.

Offline

 

#80 2009-02-20 14:56:17

yambanshee
Scratcher
Registered: 2007-11-06
Posts: 500+

Re: scratch networking commands with actionscript 2.0

golfer3 wrote:

hello people i am happy  smile

That's great, but please refrain from spamming.

Offline

 

#81 2009-02-20 15:59:33

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: scratch networking commands with actionscript 2.0

golfer3 wrote:

btw, archmage how do u get it so in your sig that it has the name of your game??

Its just an image I created.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#82 2009-02-20 16:03:58

golfer3
Scratcher
Registered: 2008-11-02
Posts: 1000+

Re: scratch networking commands with actionscript 2.0

oh, anyway i figured out how to on my own, but thx anyway

Offline

 

#83 2009-02-22 18:11:17

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: scratch networking commands with actionscript 2.0

I am having a bit of trouble sending messages to my remote pc. Here is my error message.
ReferenceError: Error #1069: Property NaN not found on flash.utils.ByteArray and there is no default value.
    at NetTest4_fla::MainTimeline/SendToScratch()
    at NetTest4_fla::MainTimeline/SendScratchSensorUpdate()
    at NetTest4_fla::MainTimeline/parseInput()
    at NetTest4_fla::MainTimeline/dataInHandler()


Here is my script

Code:

  var mySocket=new Socket();
var friendSocket=new Socket();
var dataOut:String;
var player1Connected:Boolean;
var player2Connected:Boolean;
/*var player1X:String;
var player2X:String;
var player1Y:String;
var player2Y:String;
var test:String;
*/
myStatus.text=String("Waiting to connect to your computer");
friendStatus.text=String("Waiting to connect to your friends computer");
var socketNum:int=1;
inputIP.text='192.168.1.103';

my_btn.addEventListener(MouseEvent.CLICK, enterMyIP);
function enterMyIP(evt:MouseEvent):void {
    socketNum=1;
    mySocket.connect("localhost",42001);
    mySocket.addEventListener(Event.CONNECT,socket);
    mySocket.addEventListener(Event.CLOSE,socket);
    mySocket.addEventListener(IOErrorEvent.IO_ERROR,socket);
    mySocket.addEventListener(ProgressEvent.SOCKET_DATA, dataInHandler);
}


ip_btn.addEventListener(MouseEvent.CLICK, enterIP);
function enterIP(evt:MouseEvent):void {
    socketNum=2;
    //192.168.1.103
    friendSocket.connect(inputIP.text,42001);
    friendSocket.addEventListener(Event.CONNECT,socket);
    friendSocket.addEventListener(Event.CLOSE,socket);
    friendSocket.addEventListener(IOErrorEvent.IO_ERROR,socket);
    friendSocket.addEventListener(ProgressEvent.SOCKET_DATA, fdataInHandler);
    
}

function socket(Event):void {
    if (socketNum==1) {
        switch (Event.type) {
            case 'ioError' :
                myStatus.text=String("Cannot connect to your computer");
                break;
            case 'connect' :
                myStatus.text=String("Connected to your computer");
                player1Connected=true;
                if (player1Connected==true&&player2Connected==true) {
                    SendToScratch('broadcast "StartGame"',1);
                    SendToScratch('broadcast "StartGame"',2);
                }
                break;
            case 'close' :
                myStatus.text=String("Cannot connect to your computer");
                break;
        }

    } else {
        switch (Event.type) {
            case 'ioError' :
                friendStatus.text=String("Cannot connect to your friends computer");
                break;
            case 'connect' :
                friendStatus.text=String("Connected to your friends computer");

                player2Connected=true;
                if (player1Connected==true&&player2Connected==true) {
                    SendToScratch('broadcast "StartGame"',1);
                    SendToScratch('broadcast "StartGame"',2);
                }
                break;
            case 'close' :
                friendStatus.text=String("Cannot connect to your friends computer");
                break;
        }
    }
}
//sendToScratch('broadcast "StartGame"');

function SendToScratch(dataOut:String,playerNum:int) {

    var sizeBytes:ByteArray = new ByteArray();
    sizeBytes[0]=0;
    sizeBytes[1]=0;
    sizeBytes[2]=0;
    sizeBytes[3]=dataOut.length;
    if (playerNum==1) {
        for (var i:Number=0; i<4; i++) {
            mySocket.writeByte(sizeBytes[i]);//send each element in the array to scratch
        }
        mySocket.writeMultiByte(dataOut, "us-ascii");
        mySocket.flush();

    }
    if (playerNum==2) {
        for (var j:Number=0; j<4; j++) {
            friendSocket.writeByte(sizeBytes[i]);//send each element in the array to scratch
        }
        friendSocket.writeMultiByte(dataOut, "us-ascii");
        friendSocket.flush();

    }
}


//Handle data sent from Scratch
function dataInHandler(event:ProgressEvent):void {
    var inString:String="";
    while (mySocket.bytesAvailable) {
        inString+=mySocket.readUTF();
    }
    //trace(inString);
    parseInput(inString,2);
}



//Handle data sent from Scratch
function fdataInHandler(event:ProgressEvent):void {
    var inString:String="";
    while (friendSocket.bytesAvailable) {
        inString+=friendSocket.readUTF();
    }

    parseInput(inString,1);
}


// Parse the data received from Scratch
function parseInput(input:String, socket:int) {
    // Look for broadcast from Scratch

    var pattern1:RegExp=/broadcast\s\"(\w+)\"/;
    var result:Object=pattern1.exec(input);
    if (result!=null) {
        trace('Scratch broadcasted:'+result[1]);
    }
    // Look for sensor-update from Scratch
    var pattern2:RegExp=/sensor-update\s\"Scratch-(\w+)\"\s(\w+)/;
    result=pattern2.exec(input);
    if (result!=null) {
        trace('Scratch changed variable '+result[1]+' to '+result[2]);
        SendScratchSensorUpdate(result[1],result[2],socket);
    }

}

// Send a broadcast message to Scratch
function SendScratchBroadcast(broadcast:String,socketNum:int) {
    SendToScratch('broadcast "'+broadcast+'"',socketNum);
}

// Send a sensor variable update to Scratch
function SendScratchSensorUpdate(variable:String, value:String, socketNum:int) {
    SendToScratch('sensor-update '+variable+' '+value,socketNum);
}

Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#84 2009-02-26 23:21:41

chalkmarrow
Scratcher
Registered: 2007-05-18
Posts: 100+

Re: scratch networking commands with actionscript 2.0

archmage: I probably can't direct my attention to this until the weekend, but typically this sort of NaN error happens when you try to access a non-existent array value (i.e., if you use a value that is higher than the array's dimension). You may want to look at the trace() values. In some cases perhaps the regular expressions may produce unexpected results.

Offline

 

#85 2009-02-27 14:03:08

yambanshee
Scratcher
Registered: 2007-11-06
Posts: 500+

Re: scratch networking commands with actionscript 2.0

Im still quite new with AS, but i would say, when you make the variables (first couple of lines) a lot of your strings and booleans aren't being set values, which i have found causes a lot of NaN problems for me
Edit:
you might want to run more traces where its giving you problems.

Last edited by yambanshee (2009-02-27 14:03:42)

Offline

 

#86 2009-03-08 08:42:49

s_federici
Scratcher
Registered: 2007-12-18
Posts: 500+

Re: scratch networking commands with actionscript 2.0

Guys, what are you speaking about in this post?!?!? What are Scratch networking command? Where can I start from with this, apparently awesome, new possibility of Scratch? Please, list here URLs, tutorials or whatever you like from which I will be able to start!

Offline

 

#87 2009-03-08 09:56:06

abeair
Scratcher
Registered: 2008-07-19
Posts: 100+

Re: scratch networking commands with actionscript 2.0

s_federici wrote:

Guys, what are you speaking about in this post?!?!? What are Scratch networking command? Where can I start from with this, apparently awesome, new possibility of Scratch? Please, list here URLs, tutorials or whatever you like from which I will be able to start!

go to http://scratchconnections.wik.is

Last edited by abeair (2009-03-08 09:56:50)


http://dragcave.net/image/NPtA.gif
http://www.danasoft.com/sig/ObamaLovesMacs.jpg

Offline

 

#88 2009-03-12 21:55:56

chalkmarrow
Scratcher
Registered: 2007-05-18
Posts: 100+

Re: scratch networking commands with actionscript 2.0

archmage:

I'm working on a generalized program to allow a couple instances of Scratch to communicate (using Flex 3), and, as I expected, the simplistic regular expressions I used in the above example only really handle a narrow range of what Scratch actually sends your way. Typically, the buffer may fill up with a bunch of broadcasts and sensor updates, and each sensor update may include multiple variable/value pairs. I've found that the following actionscript regular expressions work 99% of the time, if this is any help (note the use of the 'g' global flag). It also works on negative real numbers and integers:

for updates of string values:
var pattern2:RegExp = /"Scratch-(.*?)"\s"(.*?)"/g;

for updates of numeric values:
var pattern3:RegExp = /"Scratch-(.*?)"\s([-|\d|.]+)/g;

for broadcasts:
var pattern1:RegExp = /broadcast\s"(.*?)"/g;

Last edited by chalkmarrow (2009-03-12 21:57:00)

Offline

 

#89 2009-03-13 17:09:50

hamsterkirby
Scratcher
Registered: 2009-03-13
Posts: 100+

Re: scratch networking commands with actionscript 2.0

Magnie wrote:

I Can't Program At All. Only In Scratch. Everything else is too hard even squeak is too hard lol i can't even follow a tutorial right. AHHH. I'm More Of A Suggester. Archmage: I Hope You Can Do It! I Bet It Would Be Fun To Have That Part Of Scratch!

I can program a little bit on AppleScript. I am very good at programming with Scratch.


Y-100 and Y-107 shall pwn.
http://tinyurl.com/yaxc82v/.gif

Offline

 

#90 2009-03-14 02:15:16

Buddy_ca111
Scratcher
Registered: 2008-08-30
Posts: 100+

Re: scratch networking commands with actionscript 2.0

hamsterkirby wrote:

Magnie wrote:

I Can't Program At All. Only In Scratch. Everything else is too hard even squeak is too hard lol i can't even follow a tutorial right. AHHH. I'm More Of A Suggester. Archmage: I Hope You Can Do It! I Bet It Would Be Fun To Have That Part Of Scratch!

I can program a little bit on AppleScript. I am very good at programming with Scratch.

ActionScript not AppleScript sorry


By reading this you agree to giving me your soul, money, passwords, projects, abiltys and your bases

Offline

 

#91 2009-03-15 19:05:00

demosthenes
Retired Community Moderator
Registered: 2008-02-19
Posts: 1000+

Re: scratch networking commands with actionscript 2.0

I'm working on online networking using python and some php.


I've taken a long hiatus, but I still visit sometimes. Give me some time to answer any messages you post on my projects!

Offline

 

#92 2009-03-28 10:48:45

Goon94
Scratcher
Registered: 2009-03-28
Posts: 4

Re: scratch networking commands with actionscript 2.0

I use As2, and i have been looking at information about networking with flash.
Nothing i find is straight forward. Someone needs to create a tutorial that tells you how to create a multiplayer game!

Ive read about sockets, and how xml can use sockets, and how xml can link up with flash somehow, but it just doesnt tell me exactly how to use sockets!!
god!!
Although a few days ago i found out about local storage, so that should tide me over for this current game im working on.

Anyway, archmage, if you do figure out how to use sockets with As2, could you help me out... like from the very beggining.

Offline

 

#93 2009-03-28 18:00:50

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: scratch networking commands with actionscript 2.0

I usually use AS2 but I could not get it working so I learned a bit of AS3.

You can try reading this thread, it has some good advice it in.

I am not working on my connections thing at the moment but if you want to work on it I can give you the fla file.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#94 2009-03-28 19:32:52

abeair
Scratcher
Registered: 2008-07-19
Posts: 100+

Re: scratch networking commands with actionscript 2.0

archmage wrote:

I usually use AS2 but I could not get it working so I learned a bit of AS3.

You can try reading this thread, it has some good advice it in.

I am not working on my connections thing at the moment but if you want to work on it I can give you the fla file.

PLEASE do.


http://dragcave.net/image/NPtA.gif
http://www.danasoft.com/sig/ObamaLovesMacs.jpg

Offline

 

#95 2009-03-28 20:26:41

Goon94
Scratcher
Registered: 2009-03-28
Posts: 4

Re: scratch networking commands with actionscript 2.0

so its not possible with as2?
[explicitive deleted by Forum Moderator]. im not gonna relearn flash all over again !!!


as2 to the end

Offline

 

#96 2009-03-28 23:47:58

fullmoon
Retired Community Moderator
Registered: 2007-06-04
Posts: 1000+

Re: scratch networking commands with actionscript 2.0

Goon94 wrote:

so its not possible with as2?

I think there might be a bit of an unorthodox solution but I haven't tested it yet...I found an excellent program called mProjector that literally allows you to turn your .swf's into executable files, and more importantly, includes six new AS2 classes (mSystem, mApplication, mWindow, mFTP, mRegistry, mFile) that let you do more our less anything with Flash... I think mApplication.sendMessage(); might be what you're looking for. mProjector is paid software, but I've had the trial for a good three months now and it hasn't bothered me about buying it...it just won't let me compile for macs, but I've been able to write a couple of interesting apps with it. Hope this helps!


http://i302.photobucket.com/albums/nn100/fullmoon32/wow.jpg

Offline

 

#97 2009-03-28 23:53:38

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: scratch networking commands with actionscript 2.0

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


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#98 2009-03-29 01:57:34

Goon94
Scratcher
Registered: 2009-03-28
Posts: 4

Re: scratch networking commands with actionscript 2.0

that has nothing to do with networking... wow

Offline

 

#99 2009-03-29 07:13:34

yambanshee
Scratcher
Registered: 2007-11-06
Posts: 500+

Re: scratch networking commands with actionscript 2.0

Goon94 wrote:

that has nothing to do with networking... wow

umm... yea it does. Their testing sending variables through the internet for another computer to receave

Offline

 

#100 2009-03-29 12:04:07

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: scratch networking commands with actionscript 2.0

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


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

Board footer