include 'swfassist/swfassist-classes.as'; import org.libspark.web.AbstractWebGateway; import org.libspark.web.IWebRequest; import org.libspark.web.IWebResponse; import org.libspark.web.SWFResponse; import org.libspark.swfassist.swf.structures.FillStyle; import org.libspark.swfassist.swf.structures.FillStyleTypeConstants; import org.libspark.swfassist.swf.structures.LineStyle; import org.libspark.swfassist.swf.structures.SWF; import org.libspark.swfassist.swf.structures.ShapeWithStyle; import org.libspark.swfassist.swf.structures.StraightEdgeRecord; import org.libspark.swfassist.swf.structures.StyleChangeRecord; import org.libspark.swfassist.swf.tags.DefineShape2; import org.libspark.swfassist.swf.tags.PlaceObject; import org.libspark.swfassist.swf.tags.PlaceObject2; import org.libspark.swfassist.swf.tags.ShowFrame; class SwfassistGateway extends AbstractWebGateway { protected override function execute(request:IWebRequest):IWebResponse { return new SWFResponse(createSWF()); } protected function createSWF():SWF { var swf:SWF = new SWF(); swf.header.version = 9; swf.header.frameSize.xMax = 640; swf.header.frameSize.yMax = 480; swf.header.frameRate = 24; swf.header.numFrames = 1; var defineShape:DefineShape2 = new DefineShape2(); defineShape.shapeId = 1; defineShape.shapeBounds.xMax = 20; defineShape.shapeBounds.yMax = 20; var lineStyle:LineStyle = new LineStyle(); lineStyle.color.fromUint(0x333333); lineStyle.width = 1; var fillStyle:FillStyle = new FillStyle(); fillStyle.fillStyleType = FillStyleTypeConstants.SOLID_FILL; fillStyle.color.fromUint(0x666666); var shape:ShapeWithStyle = defineShape.shapes; shape.lineStyles.lineStyles.push(lineStyle); shape.fillStyles.fillStyles.push(fillStyle); var r1:StyleChangeRecord = new StyleChangeRecord(); r1.fillStyle0 = 1; r1.lineStyle = 1; r1.moveDeltaX = 0; r1.moveDeltaY = 0; r1.stateFillStyle0 = true; r1.stateLineStyle = true; r1.stateMoveTo = true; var r2:StraightEdgeRecord = new StraightEdgeRecord(); r2.verticalLine = true; r2.deltaY = 20; var r3:StraightEdgeRecord = new StraightEdgeRecord(); r3.horizontalLine = true; r3.deltaX = 20; var r4:StraightEdgeRecord = new StraightEdgeRecord(); r4.verticalLine = true; r4.deltaY = -20; var r5:StraightEdgeRecord = new StraightEdgeRecord(); r5.horizontalLine = true; r5.deltaX = -20; shape.shapeRecords.push(r1, r2, r3, r4, r5); swf.tags.addTag(defineShape); var x:Number = 320; var y:Number = 240; var placeObject:PlaceObject2 = new PlaceObject2(); placeObject.characterId = 1; placeObject.depth = 1; placeObject.matrix.translateX = x; placeObject.matrix.translateY = y; placeObject.hasCharacter = true; placeObject.hasMatrix = true; swf.tags.addTag(placeObject); swf.tags.addTag(new ShowFrame()); var expectedX:Number = x + Math.random() * 200 - 100; var expectedY:Number = y + Math.random() * 200 - 100; for (var i:uint = 0; i < 240; ++i) { var vx:Number = (expectedX - x); var vy:Number = (expectedY - y); if (Math.abs(vx) < 0.1 && Math.abs(vy) < 0.1) { x = expectedX; y = expectedY; expectedX = x + Math.random() * 200 - 100; expectedY = y + Math.random() * 200 - 100; } else { x += vx / 3; y += vy / 3; } var placeObject:PlaceObject2 = new PlaceObject2(); placeObject.depth = 1; placeObject.isMove = true; placeObject.matrix.translateX = x; placeObject.matrix.translateY = y; placeObject.hasMatrix = true; swf.tags.addTag(placeObject); swf.tags.addTag(new ShowFrame()); ++swf.header.numFrames; } return swf; } } new SwfassistGateway().enter();