In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Stringをunion serverに送って保存するコード

UnionのRoomにStringを保存する参考コード。
Get Adobe Flash player
by keno42 05 Apr 2011
/**
 * Copyright keno42 ( http://wonderfl.net/user/keno42 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/iU6C
 */

// UnionのRoomにStringを保存する参考コード。
// forked from keno42's loaderInfo.parameters on wonderfl
package {
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // localhostに実際のホスト名を入れれば動作します
            new StringLog("wonderfl.myLog", String(Math.random()), "localhost", 9100);
        }
    }
}

import net.user1.reactor.*;
class StringLog{
    private var r:Reactor = new Reactor();
    function StringLog(roomName:String, msg:String, serverName:String, port:int){
        r.addEventListener(ReactorEvent.READY, function(e:ReactorEvent):void{
            var roomSettings:RoomSettings = new RoomSettings();
            roomSettings.removeOnEmpty = false;
            var room:Room = r.getRoomManager().createRoom(roomName, roomSettings);
            room.addEventListener(RoomEvent.JOIN, function(e:RoomEvent):void{
                var log:String = room.getAttribute("log");
                log += msg + "\n";
                room.addEventListener(AttributeEvent.UPDATE, onUpdate);
                room.setAttribute("log", log);
            });
            room.join();
        });
        r.connect(serverName, port);
    }
    private function onUpdate(e:AttributeEvent):void{
        // 呼び出し元に返すにはEventDispatcherを使ってください
        trace(e.getChangedAttr().value);
        r.disconnect();
    }
}