B4J Question [SOLVED][ABMaterial] ABMCanvasObject Clickable Event Syntax?

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

what is the syntax of the Clickable Event for a Canvas Object?

Tried below _Clicked and _ObjectClicked (found in abmcanvas.4.25.min.js) but there is no logentry when clicked. The mouse pointer changes to a hand, so clickable is recognized for the object.
The objects, valve, are created in the sub BuildValve. See below.
upload_2018-7-14_12-54-19.png


B4X:
Sub canvasValveIn_Clicked(objectId As String)
   Log("canvasValveIn clicked:" & objectId)
End Sub

Sub canvasValveIn_ObjectClicked(objectId As String)
   Log("canvasValveIn object clicked:" & objectId)
End Sub

The objects are defined as global to handle the events:
B4X:
Dim canvasValveIn As ABMCanvasObject
Dim canvasValveOut As ABMCanvasObject

Adding the two canvas objects canvasValveIn and canvasValveOut to the canvas in ConnectPage().
B4X:
Dim canvasTankFarm As ABMCanvas
canvasTankFarm.Initialize(page, "canvasTankFarm", ABM.COLOR_TRANSPARENT, ABM.INTENSITY_NORMAL, 400,400, False)
canvasValveIn = BuildValve("canvasValveIn",50,10,10)
canvasValveOut = BuildValve("canvasValveOut",50,50,10)
canvasTankFarm.AddObject(canvasValveIn)
canvasTankFarm.AddObject(canvasValveOut)
page.Cell(1,1).AddComponent(canvasTankFarm)

Canvas Object building a Valve
B4X:
Sub BuildValve(id As String, valvex As Int, valvey As Int, valvewidth As Int) As ABMCanvasObject
   Dim valve As ABMCanvasObject
   Dim linestrokecolor As String = ABM.COLOR_RED   '"#888888"
   valve.InitializeAsRectangle(page, id, valvex,valvey,valvewidth,valvewidth,True)
   valvex = 0
   valvey = 0
   valve.beginPath
   valve.lineWidth(1)
   valve.lineCap(ABM.CANVAS_LINECAP_SQUARE)
   valve.strokeStyleColor(linestrokecolor)
   'TopLeft to BottomRight
   valve.moveTo(valvex,valvey)
   valve.lineTo(valvex+valvewidth,valvey+valvewidth)
   'BottomRight to TopRight
   valve.moveTo(valvex+valvewidth,valvey+valvewidth)
   valve.lineTo(valvex+valvewidth,valvey)
   'TopRight to BottomLeft
   valve.moveTo(valvex+valvewidth,valvey)
   valve.lineTo(valvex,valvey+valvewidth)
   'BottomLeft to TopLeft
   valve.moveTo(valvex, valvey+valvewidth)
   valve.lineTo(valvex,valvey)
   ' MiddleMiddle to TopMiddle
   valve.moveTo(valvex+(valvewidth/2), valvey+(valvewidth/2))
   valve.lineTo(valvex+(valvewidth/2),valvey)
   valve.strokeStyleColor(linestrokecolor)
   valve.Clickable = True
   valve.stroke
   Return valve
End Sub
 
Last edited:

rwblinn

Well-Known Member
Licensed User
Longtime User
Thats it. When clicking on a valve, the log shows:
B4X:
(MyMap) {eventparams=objectid, eventname=canvastankfarm_objectclicked, objectid=canvasvalvein}

which means, following event is required:
B4X:
Sub canvasTankFarm_ObjectClicked(objectId As String)
   Log("canvasTankFarm objectclicked clicked:" & objectId)
End Sub

resulting in:
B4X:
canvasTankFarm objectclicked clicked:canvasvalvein
canvasTankFarm objectclicked clicked:canvasvalveout
...

The events canvasValveIn_xxx and canvasValveOut_ are not required.

Good learning = Thanks for the hint!
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Maybe put a log eventname in parseEvent
Not "maybe" - you should "always" (as in alwaysbusy)...

That was the first trick I learned and quite frankly without it, I never would have figured out very much...

Thanks
 
Upvote 0
Top