I have been exploring the content of this article: which details how to create a native cursor in AIR without resorting to using a sprite to mimic the functionality.
However, my project is based on HTML/JavaScript rather than ActionScript.
Here is the code I have so far:
function nativeCursor(){
// load in a bitmap
var loader = new air.Loader();
loader.load(new air.URLRequest('./assets/cursor.png'));
var bitmaps = new air.Vector["<String>"]();
var bmd = new air.BitmapData(32, 32, true, 0x00000000);
var p = new window.runtime.flash.geom.Point(0, 0);
var r = new window.runtime.flash.geom.Rectangle(32 , 0, 32, 32);
var image = new window.runtime.flash.display.Bitmap(loader.content);
bmd.copyPixels([image.bitmapData], r, p);
bitmaps.push(bmd);
var mcd = new window.runtime.flash.ui.MouseCursorData();
mcd.data = bitmaps;
mcd.hotSpot = new Point(0, 0);
mcd.frameRate = 24;
window.runtime.flash.ui.Mouse.registerCursor("defaultCursor", mcd);
window.runtime.flash.ui.Mouse.cursor = "defaultCursor";
}
However, I encounter an error
TypeError: Error #1034: Type Coercion failed: cannot convert []@2b9d1f1 to flash.display.BitmapData.
when reaching this line: bmd.copyPixels([image.bitmapData], r, p);
If I remove the brackets from that line so it reads:
bmd.copyPixels(image.bitmapData, r, p);
, the error changes to TypeError: Error #2007: Parameter sourceBitmapData must be non-null.
I suspect that the issue lies in the bitmap data being null, but why is this happening? The image loads successfully, so perhaps my approach to accessing the bitmap data is incorrect?