Apache flex 是否将鼠标光标更改为位图(Flex 4)?
在Flex4中,如何将光标更改为运行时确定的位图图像?我看到的所有示例都使用CursorManager.setCursor将游标设置为编译时指定的类 我要做的是将光标更改为位图,其位图数据由上下文确定Apache flex 是否将鼠标光标更改为位图(Flex 4)?,apache-flex,flex4,Apache Flex,Flex4,在Flex4中,如何将光标更改为运行时确定的位图图像?我看到的所有示例都使用CursorManager.setCursor将游标设置为编译时指定的类 我要做的是将光标更改为位图,其位图数据由上下文确定 package cursor { import flash.display.BitmapData; import flash.display.PixelSnapping; import mx.core.BitmapAsset; public class RuntimeBitmap1 exten
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);
用法:
var bitmapData:BitmapData = new BitmapData(50, 50, false, 0x88888888);
RuntimeBitmap1.staticBitmapData = bitmapData;
cursorManager.setCursor(RuntimeBitmap1, 0);
以下是使用位图图像更改默认光标的几个简单步骤:
var DEFAULT_CURSOR_IMAGE : Class;
var myCursorBitmap : Bitmap;
...
myCursorBitmap = new DEFAULT_CURSOR_IMAGE();
var DEFAULT\u CURSOR\u IMAGE:Class;
var-myCursorBitmap:位图;
...
myCursorBitmap=新的默认光标图像()
function onMouseMove(event : MouseEvent) : void
{
myCursorBitmap.x = event.localX;
myCursorBitmap.y = event.localY;
}
mouseMove函数(事件:MouseEvent):void
{
myCursorBitmap.x=event.localX;
myCursorBitmap.y=event.localY;
}
addChild(myCursorBitmap);
...
myCursorBitmap.bitmapData = myNewCursor;
addChild(myCursorBitmap);
...
myCursorBitmap.bitmapData=myNewCursor
要还原默认光标,请从后台删除光标位图并调用Mouse.show()。以下是使用位图图像更改默认光标的几个简单步骤:
var DEFAULT_CURSOR_IMAGE : Class;
var myCursorBitmap : Bitmap;
...
myCursorBitmap = new DEFAULT_CURSOR_IMAGE();
var DEFAULT\u CURSOR\u IMAGE:Class;
var-myCursorBitmap:位图;
...
myCursorBitmap=新的默认光标图像()
function onMouseMove(event : MouseEvent) : void
{
myCursorBitmap.x = event.localX;
myCursorBitmap.y = event.localY;
}
mouseMove函数(事件:MouseEvent):void
{
myCursorBitmap.x=event.localX;
myCursorBitmap.y=event.localY;
}
addChild(myCursorBitmap);
...
myCursorBitmap.bitmapData = myNewCursor;
addChild(myCursorBitmap);
...
myCursorBitmap.bitmapData=myNewCursor
要恢复默认光标,请从后台删除光标位图并调用Mouse.show()。我想将UIComponent绘制为光标 我把格言和答案结合在一起。我对Maxim答案所做的唯一更改如下:
public function RuntimeBitmap1()
{
super(RuntimeBitmap1.staticBitmapData);
}
否则,staticBitmapData在构造函数中以null的形式出现。我想画一个UIComponent作为光标 我把格言和答案结合在一起。我对Maxim答案所做的唯一更改如下:
public function RuntimeBitmap1()
{
super(RuntimeBitmap1.staticBitmapData);
}
否则,staticBitmapData在构造函数中显示为null。这是一个Flex项目,因此我无法将Child添加到主mxml类。@justkevin:是的,你说得对-在这种情况下,你必须将其放置在UIComponent中。这是一个Flex项目,因此我无法将Child添加到主mxml类。@justkevin:是的,你说得对——在这种情况下,你必须把它放在一个UIComponent中。