I have coded a bit more and just want to show some of the progress.
The following is what you write in Java (and it compiles with the help from stub classes):
package com.springworldgames.javatoas3.testfiles;
import com.springworldgames.javatoas3.as3replacers.EventFunction;
import flash.display.BlendMode;
import flash.display.CapsStyle;
import flash.display.Graphics;
import flash.display.LineScaleMode;
import flash.display.Sprite;
import flash.events.Event;
import flash.ui.Mouse;
public class ch7ex1 extends Sprite {
protected Sprite compass;
protected Sprite crosshairs;
public ch7ex1() {
drawCompass();
drawCrosshairs();
addEventListener(Event.ENTER_FRAME, tick);
}
EventFunction tick = new EventFunction() {
@Override
public void eventFunction(Event event) {
Mouse.hide();
crosshairs.x = stage.mouseX;
crosshairs.y = stage.mouseY;
compass.rotation = Math.atan2(stage.mouseY - compass.y,
stage.mouseX - compass.x)
* 180 / Math.PI;
}
};
protected void drawCompass() {
double RADIUS = 30;
compass = new Sprite();
Graphics g = compass.graphics;
g.lineStyle(4, 0xe03030);
g.beginFill(0xd0d0d0);
g.drawCircle(0, 0, RADIUS);
g.endFill();
g.moveTo(0, 0);
g.lineTo(RADIUS, 0);
addChild(compass);
compass.x = stage.stageWidth / 2;
compass.y = stage.stageHeight / 2;
}
protected void drawCrosshairs() {
double SIZE = 10;
crosshairs = new Sprite();
Graphics g = crosshairs.graphics;
g
.lineStyle(8, 0x4040f0, 1, false, LineScaleMode.NONE,
CapsStyle.SQUARE);
g.moveTo(0, SIZE);
g.lineTo(0, -SIZE);
g.moveTo(SIZE, 0);
g.lineTo(-SIZE, 0);
crosshairs.blendMode = BlendMode.MULTIPLY;
addChild(crosshairs);
}
}
The following is the ActionScript 3 result:
package com.springworldgames.javatoas3.testfiles {
import flash.display.BlendMode;
import flash.display.CapsStyle;
import flash.display.Graphics;
import flash.display.LineScaleMode;
import flash.display.Sprite;
import flash.events.Event;
import flash.ui.Mouse;
public class ch7ex1 extends Sprite {
protected var compass:Sprite;
protected var crosshairs:Sprite;
public function ch7ex1() {
drawCompass();
drawCrosshairs();
addEventListener(Event.ENTER_FRAME, tick);
}
public function tick(event:Event):void {
Mouse.hide();
crosshairs.x = stage.mouseX;
crosshairs.y = stage.mouseY;
compass.rotation = Math.atan2(stage.mouseY - compass.y, stage.mouseX - compass.x) * 180 / Math.PI;
}
protected function drawCompass():void {
var RADIUS:Number = 30;
compass = new Sprite();
var g:Graphics = compass.graphics;
g.lineStyle(4, 0xe03030);
g.beginFill(0xd0d0d0);
g.drawCircle(0, 0, RADIUS);
g.endFill();
g.moveTo(0, 0);
g.lineTo(RADIUS, 0);
addChild(compass);
compass.x = stage.stageWidth / 2;
compass.y = stage.stageHeight / 2;
}
protected function drawCrosshairs():void {
var SIZE:Number = 10;
crosshairs = new Sprite();
var g:Graphics = crosshairs.graphics;
g.lineStyle(8, 0x4040f0, 1, false, LineScaleMode.NONE, CapsStyle.SQUARE);
g.moveTo(0, SIZE);
g.lineTo(0, -SIZE);
g.moveTo(SIZE, 0);
g.lineTo(-SIZE, 0);
crosshairs.blendMode = BlendMode.MULTIPLY;
addChild(crosshairs);
}
}
}
The example is from the ActionScript 3.0 Bible second edition. I think I will go through all the examples in that book and try to translate Java code into them.
I am aware that it will not become a general tool for all possible ways to work with ActionScript and Java, but hopefully it will transform into a fairly useful compromise.