Skip to main content
Participant
October 2, 2009
Question

Drawing application and shared object

  • October 2, 2009
  • 2 replies
  • 812 views

Hey,


I'm trying out this tutorial (my first steps with Flash and ActionScript): http://www.adobe.com/devnet/flashcom/articles/whiteboard.html

I added clear button, which clears all lines from user's whiteboard, but every other user who is connected to whiteboard, still sees lines. But when other users refresh the page, lines are gone too. That means I'm able to delete data from shared object, but I don't know how to update other users' whiteboard.

Here's the code I use to clear whiteboard:

function initClearButton() {
    button_clear.onRelease = function() {
        do_clear = true;
        for (i in drawing_so.data) {
            drawing_so.data = null;
        }
        init();
    }
}

Basically, that's all I have added to tutorial code. What do I need to do to get other users' whiteboard updated/cleared?

    This topic has been closed for replies.

    2 replies

    sannu1Author
    Participant
    October 6, 2009

    I finally got that problem solved. Here's the code:

    function initClearButton() {
        button_clear.onRelease = function() {
            do_clear = true;
            for (i in drawing_so.data) {
                drawing_so.data = null;
            }
            init();
        }
    }

    And to initSharedObject, I had to add some lines:

    function initSharedObject() {
        main_nc = new NetConnection();

        main_nc.onStatus = function(info) {
            if (info.code == "NetConnection.Connect.Success") {
                drawing_so = SharedObject.getRemote("drawing" + _level0.someCode, main_nc.uri, true);
                drawing_so.onSync = function(list) {
                    for (var n in list) {
                        var line_obj = this.data[list.name];

                        if (line_obj == null) {
                            //stop execution of update and clear
                            init();
                            return;
                        }

                        draw_line_mc.moveTo(line_obj.x1, line_obj.y1);
                        draw_line_mc.lineTo(line_obj.x2, line_obj.y2);
                    }
                };
                drawing_so.connect(main_nc);
            } else {
                trace("ERROR: " + info.code);
            }
        };

        main_nc.connect("rtmp:/drawing", _level0.someCode);
    }

    Thanks Eero for helping me

    ghost31379
    Inspiring
    October 3, 2009

    hrmmm.....i looked at that code you were doing....and for some strange reason I didnt see where you got that code from below......nonetheless.....I cant remember off hand how to do that with a sharedObject...must be sleepy time.......either way.....

    the easiest way I can see to accomplish this would be to have a function that clears like....."theClearFunction" inside of everybody's main class......and have a function on the server side that triggers it and calls "theClearFunction" on everybody who is connected to the application.

    simplest way for me and easier to organize in my brain.....

    thelegendaryghost