rather than show what I’ve tried, here are some code snippets. How do I get the image id on mousedown in HTML5?
(note: don’t know why the comments are not alligned, there are no tabs in the source)
<!DOCTYPE html>
...
<canvas id='canvas' width='600' height='300'>
Canvas not supported
</canvas>
<script type="text/javascript">
// ----- Globals -----
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d');
canvas.addEventListener("mousedown", GetSourceIndex, false);
...
function DisplayCard(card, xPos, yPos){ // show card on canvas
var img = new Image();
img,id="someid"; // IMAGE ID ASSIGNED HERE
img.src = card.ordinal + card.suit + ".gif"; // build file name
img.onload = function() { // wait for image to load
context.drawImage(img, xPos, yPos); // place it on canvas
} // end onload
} // end function DisplayCard
...
function GetSourceIndex(e) { // mousedown event (card to move)
// WANT TO GET THE image's ID HERE.
...
(the img.id=“someid” is simply to show where I would build then assign an id)
I’m expecting there is an additional argument to add to the addEventListener and/or argument to the GetSourceIndex function. But so far, despite intense Googling, I’ve had no luck in finding the solution…
grNadpa