在Flex 4中,如何将光标更改为在运行时确定的位图图像?我见过的所有示例都使用CursorManager.setCursor将游标设置为编译时指定的类。
我想要做的是将光标更改为位图,其位图数据由上下文确定。
答案 0 :(得分:2)
package cursor
{
import flash.display.BitmapData;
import flash.display.PixelSnapping;
import mx.core.BitmapAsset;
public class RuntimeBitmap1 extends BitmapAsset
{
public static var staticBitmapData:BitmapData;
public function RuntimeBitmap1()
{
super(staticBitmapData);
}
}
}
用法:
var bitmapData:BitmapData = new BitmapData(50, 50, false, 0x88888888);
RuntimeBitmap1.staticBitmapData = bitmapData;
cursorManager.setCursor(RuntimeBitmap1, 0);
答案 1 :(得分:1)
我想将UIComponent绘制为游标。
我使用Maxims答案和Flex Cookbox article的组合来管理它。我必须对Maxim回答的唯一改变是:
public function RuntimeBitmap1()
{
super(RuntimeBitmap1.staticBitmapData);
}
否则staticBitmapData在构造函数中为null。
答案 2 :(得分:0)
以下是使用位图图像更改默认光标的几个简单步骤:
var DEFAULT_CURSOR_IMAGE : Class;
var myCursorBitmap : Bitmap;
...
myCursorBitmap = new DEFAULT_CURSOR_IMAGE();
function onMouseMove(event : MouseEvent) : void
{
myCursorBitmap.x = event.localX;
myCursorBitmap.y = event.localY;
}
使用Mouse.hide()隐藏真实光标。
显示自定义光标。您可以稍后通过动态设置bitmapData来更新光标形状。
addChild(myCursorBitmap);
...
myCursorBitmap.bitmapData = myNewCursor;
要恢复默认光标,请从舞台中删除光标位图,然后调用Mouse.show()。