flash on 2010-1-17
♥1 |
Line 229 |
Modified 2010-01-19 21:00:27 |
MIT License
archived:2017-03-10 02:42:18
ActionScript3 source code
/**
* Copyright venthels ( http://wonderfl.net/user/venthels )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/dhHw
*/
package {
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.AsyncErrorEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.events.SyncEvent;
import flash.geom.Point;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.ObjectEncoding;
import flash.net.SharedObject;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
public class sotest extends Sprite {
private var nc:NetConnection;
private var ns:NetStream;
private var maxNum:int = 20;
private var objAry:Array = new Array();
private var so:SharedObject;
private var soAry:Array = new Array();
private var devNum:uint = 4;
private var recFlg:Array = new Array(devNum);
private var PrecFlg:Array = new Array(devNum);
//private var devPtAry:Array = new Array(devNum);
//private var testPt:Array = new Array(devNum);
private var tf:TextField = new TextField();
private var ttf:TextField = new TextField();
public var base:Sprite = new Sprite();
private var shape:Shape = new Shape();
private var objPtAry:Array = new Array();
//private var ktdm:kotodama = new kotodama();
//ID Max 3
private var my_ID:uint = 3;
public function sotest():void {
connect();
//initSO();
stage.addChild(tf);
tf.autoSize = TextFieldAutoSize.LEFT;
stage.addChild(ttf);
ttf.autoSize = TextFieldAutoSize.LEFT;
//ttf.x = stage.stageWidth;
ttf.x = 300;
stage.addChild(base);
base.x = 0;
base.y = 0;
nc.addEventListener(NetStatusEvent.NET_STATUS, onNcNetStatusEvent);
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onNcAsyncErrorEvent);
nc.addEventListener(IOErrorEvent.IO_ERROR, onNcIOErrorEvent);
}
private function connect():Boolean {
nc = new NetConnection();
nc.objectEncoding=ObjectEncoding.AMF0;//竊舌さ繝ャ驥崎ヲ・
//nc.connect('rtmp://localhost/test');
trace("client : "+nc.client);
trace("uri : "+nc.uri);
return nc.connected;
}
private function onNcNetStatusEvent(evt:NetStatusEvent):void {
switch(evt.info.code) {
case "NetConnection.Connect.Success":
trace("繧「繝励Μ繧ア繝シ繧キ繝ァ繝ウ縺ク縺ョ謗・邯壹′謌仙粥縺励∪縺励◆縲・");
initSO();
break;
case "NetConnection.Connect.Failed":
trace("繧「繝励Μ繧ア繝シ繧キ繝ァ繝ウ縺ク縺ョ謗・邯壹′螟ア謨励@縺セ縺励◆縲・");
break;
case "NetConnection.Connect.Rejected":
trace("繧「繝励Μ繧ア繝シ繧キ繝ァ繝ウ縺ォ謗・邯壹☆繧区ィゥ髯舌′縺ゅj縺セ縺帙s縲・");
break;
case "NetConnection.Connect.Closed":
trace("繧「繝励Μ繧ア繝シ繧キ繝ァ繝ウ縺ク縺ョ謗・邯壹′辟。莠玖ァ」髯、縺輔l縺セ縺励◆縲・");
break;
case "NetConnection.Connect.InvalidApp":
trace("繧「繝励Μ繧ア繝シ繧キ繝ァ繝ウ蜷阪′辟。蜉ケ縺ァ縺吶・");
default:
trace(evt.info.code);
break;
}
}
private function onNcAsyncErrorEvent(evt:AsyncErrorEvent):void {
trace("AsyncErrorEvent 繧ィ繝ゥ繝シ");
trace(evt.toString());
}
private function onNcIOErrorEvent(evt:IOErrorEvent):void {
trace("IOErrorEvent 繧ィ繝ゥ繝シ");
}
private function initSO():void{
so = SharedObject.getRemote("ball", nc.uri, true );
so.connect(nc);
//so.fps = 20;
//so.clear();
////...MAKE SHARED OBJECT...////
var Ary:Array = new Array();
so.setProperty("DevPt", Ary);
so.setProperty("DevRec", Ary);
so.setProperty("DevAL", Ary);
so.setProperty("TestSet", Ary);
//so.setProperty("Obj", Ary);
so.addEventListener(SyncEvent.SYNC, sync);
stage.addEventListener(Event.ENTER_FRAME, loop);
//////////////////////////////////////////////////////////
//Device ( Smole Baby ) by.ore
stage.addEventListener(MouseEvent.MOUSE_MOVE, MM);
stage.addEventListener(MouseEvent.MOUSE_DOWN, MD);
stage.addEventListener(MouseEvent.MOUSE_UP, MU);
}
private function MM(e:MouseEvent):void {
////...SEND DEVICE POINT...////
try {
so.data.DevPt[my_ID] = new Point(base.mouseX, base.mouseY);
so.setDirty("DevPt");
}
catch(e:Error) {
}
}
private function MD(e:MouseEvent):void {
////....SEND REC FLG...////
try {
so.data.DevRec[my_ID] = true;
so.setDirty("DevRec");
}
catch(e:Error) {
}
////...SEND ACTIVE LEVEL...////
var testRandom:int = 5+Math.random()*20;
try {
so.data.DevAL[my_ID] = testRandom;
so.setDirty("DevAL");
}
catch(e:Error) {
}
}
private function MU(e:MouseEvent):void {
////...SEND REC FLG...////
try {
so.data.DevRec[my_ID] = false;
so.setDirty("DevRec");
}
catch(e:Error) {
}
////...KOTODAMA SET FLG (TEST)...////
try {
so.data.TestSet[my_ID] = true;
so.setDirty("TestSet");
}
catch(e:Error) {
}
}
private function sync(evt:SyncEvent):void {
}
private function loop(e:Event):void {
var ttxt:String = "My Device Property\n";
try {
ttxt += "ID= "+String(my_ID);
ttxt += " Pt "+String(so.data.DevPt[my_ID])+"\n";
ttxt += "Object Property\n";
//trace(so.data.Obj);
for(var i:int=0; i<so.data.Obj.length; i++) {
ttxt += String(i);
var myPt:Point = new Point(so.data.DevPt[my_ID].x, so.data.DevPt[my_ID].y);
var tPt:Point = new Point(so.data.Obj[i].pt.x, so.data.Obj[i].pt.y);
var dis:uint = Point.distance(myPt, tPt);
ttxt += ": dist= "+String(dis);
//ttxt += ": x: "+String(so.data.Obj[i]);
//ttxt += ": y: "+String(so.data.Obj[i].yy);
ttxt += "\n";
}
}
catch(e:Error) {
ttxt += "\n Error";
}
ttf.text = ttxt;
//////////////////////////////////////////////////
////////////////////////////////////////////////
//...Projection ( Big Mama ) by.ore
stage.addChild(shape);
var g:Graphics = shape.graphics;
g.clear();
//g.lineStyle (1, 0x000000, 1.0);
var txt:String = "Device Property\n";
try {
for(var i:int=0; i<devNum; i++) {
txt += String(i);
//if(so.data.Dev.ID == i) {
txt += ": x: "+String(so.data.DevPt[i].x);
txt += ": y: "+String(so.data.DevPt[i].y);
if(so.data.DevRec[i]) {
txt += " REC";
g.beginFill (0xff0000, 1.0);
g.drawCircle(so.data.DevPt[i].x, so.data.DevPt[i].y, so.data.DevAL[i]);
}
else {
g.beginFill (0x666666, 1.0);
g.drawCircle(so.data.DevPt[i].x, so.data.DevPt[i].y, 5);
////...MAKE KOTODAMA...////
if(so.data.TestSet[i]) {
trace(i+" :NEW_ktdm");
//var sp:Sprite = new Sprite();
//sp.x = so.data.DevPt[i].x;
//sp.y = so.data.DevPt[i].y;
//stage.addChild(sp);
var makePt:Point = new Point(so.data.DevPt[i].x, so.data.DevPt[i].y);
objAry.push(new kotodama(base, makePt, so.data.DevAL[i]));
so.setProperty("Obj", objAry);
so.data.TestSet[i] = false;
}
}
//}
txt += "\n";
}
//PrecFlg = recFlg;
txt += "Obj Num = " + String(objAry.length) + "\n";
}
catch(e:Error) {
txt += "\n Error";
}
tf.text = txt;
///////////////////////////////////////////////////////
}
}
}
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.geom.Point;
import flash.utils.Timer;
class kotodama extends Sprite {
private var my_sh:Shape;
private var sp:Sprite;
public var pt:Point;
private var al:uint;
//public var xx,yy:int;
public var sz:Number;
private var timer:Timer;
public function kotodama(_sp:Sprite, _pt:Point, _al:int):void {
sp = _sp;
pt = _pt;
sz = _al;
my_sh = new Shape();
//sh.name = String(id);
my_sh.graphics.clear();
my_sh.graphics.beginFill (0x000099, 1.0);
my_sh.graphics.drawCircle (pt.x, pt.y, sz);
sp.addChild(my_sh);
timer = new Timer(100);
timer.addEventListener(TimerEvent.TIMER, loop);
timer.start();
//my_sh.addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(event:Event):void {
pt.x += (0.5-Math.random()) * 1;
pt.y += (0.5-Math.random()) * 1;
//sz = sz/1.01;
if(sz <= 1.5)
sz -= 0.2;
if(sz <= 0)
sz = 0;
my_sh.graphics.clear();
my_sh.graphics.beginFill (0x000099, 1.0);
my_sh.graphics.drawCircle (pt.x, pt.y, sz);
//xx = my_sh.x;
//yy = my_sh.y;
}
}