在Flash Player 10.2中使用原生鼠标指针
Adobe Flash Player 10.2 版本引入了一个引人注目的新特性:原生鼠标指针。您现在可以使用运行在操作系统层的基于位图的鼠标指针。
实现原生鼠标指针
flash.ui 包中的 MouseCursorData 对象
MouseCursorData 对象的三个属性:
MouseCursorData.data:用于显示鼠标指针的 BitmapData 对象向量。
MouseCursorData.hotSpot:鼠标指针的定位点值,保存为一个 Point 对象。
MouseCursorData.frameRate:用于实现位图图像序列动画的帧频。这个属性允许您创建动画鼠标指针。
在创建一个 MouseCursorData 对象之后,您要使用 Mouse.registerCursor 方法将它赋值给 Mouse 对象。一旦注册了 Mouse 对象,您可以将别名传递给 Mouse.cursor 属性。
说明:通过传递一个 BitmapData ,您就可以通过指定一系列的位图鼠标指针来创建一个原生的动画指针。
请查看以下示例代码:
// Create a MouseCursorData objectvar cursorData:MouseCursorData = new MouseCursorData();// Specify the hotspotcursorData.hotSpot = new Point(15,15);// Pass the cursor's bitmap to a BitmapData Vectorvar bitmapDatas:Vector.<BitmapData> = new Vector.<BitmapData>(3, true);// Create the bitmap cursor frames// Bitmaps must be 32 x 32 pixels or less, due to an OS limitationvar frame1Bitmap:Bitmap = new frame1();var frame2Bitmap:Bitmap = new frame2();var frame3Bitmap:Bitmap = new frame3();// Pass the values of the bitmap files to the bitmapDatas vectorbitmapDatas[0] = frame1Bitmap.bitmapData;bitmapDatas[1] = frame2Bitmap.bitmapData;bitmapDatas[2] = frame3Bitmap.bitmapData;// Assign the bitmap data to the MouseCursor objectcursorData.data = bitmapDatas;// Pass the frame rate of the animated cursor (1fps)cursorData.frameRate = 1;// Register the MouseCursorData to the Mouse objectMouse.registerCursor("myAnimatedCursor", cursorData);// When needed for display, pass the alias to the existing cursor propertyMouse.cursor = "myAnimatedCursor";通过设置 MouseCursorData.frameRate 属性并传入一系列 BitmapData 对象,Flash Player 就会自动创建出一个以指定帧频播放的动画鼠标指针。这是一个自动化的过程,所以您不需要编写任何代码就能够实现动画鼠标指针。