
Код AS3:
var telepathist:Telepathist = new Telepathist();
telepathist.addEventListener(TelepathistEvent.CONNECT, onConnect);
telepathist.connectToClient();
private function onConnect(event:TelepathistEvent):void
{
var thoughts:Thoughts = (event.target as Telepathist).readThoughts(event.client);
var ba:ByteArray = WonderScriptBox.makeResult(thoughts);
var ref:FileReference = new FileReference();
ref.save(ba, 'Main.as');
}
// Main.as
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
public class Main extends Sprite
{
private const LINE_THICKNESS:int = 3;
private const LINE_COLOR:uint = 0x000000;
private var points:Array;
public function Main()
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(event:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
points = [];
stage.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(event:MouseEvent):void
{
var point:Point = new Point(event.stageX, event.stageY);
points.push(point);
if (points.length > 1)
{
var p1:Point = points[points.length - 2];
var p2:Point = points[points.length - 1];
graphics.lineStyle(LINE_THICKNESS, LINE_COLOR);
graphics.moveTo(p1.x, p1.y);
graphics.lineTo(p2.x, p2.y);
}
}
}
}