Hello,
I would post this on StackOverflow but Haxe is not that popular so I’m trying here. Thanks in advance for the help!
My error is "src/Main.hx:62 characters 19-23 : Cannot access private field isColorOn"
My modules are Main.hx and GridItem.hx
=======================================================
GridItem.hx
package src;
import openfl.display.Graphics;
import openfl.display.Sprite;
import openfl.events.MouseEvent;
class GridItem extends Sprite {
var circle:Sprite;
var offColor:UInt = 0xF1F1F1;
var onColor:UInt = 0xD3D3D3;
var circleRadius:UInt = 11;
var isColorOn:Bool = false;
public function new() {
super();
circle = new Sprite();
this.addChild(circle);
colorOff();
}
public function setRadius(circleRadius:UInt) {
this.circleRadius = circleRadius;
}
function colorCircle(color:UInt) {
var g:Graphics = circle.graphics;
g.clear();
g.beginFill (color);
g.drawCircle (circleRadius, circleRadius, circleRadius);
g.endFill();
}
public function getColorState():Bool {
return isColorOn;
}
public function colorOff() {
isColorOn = false;
colorCircle(offColor);
}
public function colorOn() {
isColorOn = true;
colorCircle(onColor);
}
}
=======================================================
Main.hx
package;
import openfl.display.Sprite;
import openfl.events.MouseEvent;
import src.GridItem;
class Main extends Sprite {
var isMouseDown:Bool;
var isWantedColor:Bool;
public function new () {
super ();
init();
}
function init() {
var gridItem:GridItem;
var numRows:UInt = 10;
var numCols:UInt = 10;
var _circleRadius:Int = 11;
var circleMargin:Int = 1;
var offset:Int = _circleRadius * 2 + circleMargin * 2;
for (row in 0...numRows) {
for (column in 0...numCols) {
gridItem = new GridItem();
gridItem.setRadius(_circleRadius);
gridItem.x = offset * column;
gridItem.y = offset * row;
gridItem.addEventListener (MouseEvent.MOUSE_DOWN, onCircleDragStart);
gridItem.addEventListener (MouseEvent.MOUSE_OVER, onCircleDragOver);
this.addChild(gridItem);
}
}
}
function setColor(gridItem:GridItem) {
if (isWantedColor) {
gridItem.colorOn();
}
else {
gridItem.colorOff();
}
}
function onCircleDragStart(e:MouseEvent):Void {
isMouseDown = true;
var gridItem:GridItem = cast e.currentTarget;
isWantedColor = !gridItem.isColorOn;
setColor(gridItem);
stage.addEventListener(MouseEvent.MOUSE_UP, onCircleDragEnd);
}
function onCircleDragOver(e:MouseEvent):Void {
if (isMouseDown) {
var gridItem:GridItem = cast e.currentTarget;
setColor(gridItem);
}
}
private function onCircleDragEnd(e:MouseEvent):Void {
isMouseDown = false;
stage.removeEventListener(MouseEvent.MOUSE_UP, onCircleDragEnd);
}
}