开发者

Optionally use Flash 10.2 cursors, while still being compatible with Flash 10.0?

开发者 https://www.devze.com 2023-02-02 23:07 出处:网络
I have a Flash application that requires Flash version 10.0 to run. I want to add native mouse cursors, which were introduced in Flash 10.2, but I don\'t want to require all my users to upgrade, and I

I have a Flash application that requires Flash version 10.0 to run. I want to add native mouse cursors, which were introduced in Flash 10.2, but I don't want to require all my users to upgrade, and I don't want to have to compile two separate versi开发者_如何学Cons of my app.

Is there any way at runtime I can detect if the cursors are available, and then use them?

It seems like if you only compile for Flash 10.0, it marks the SWF version header "10", and you have no access to the new APIs. And if you compile for Flash 10.2, it marks the version header "11", and you have access to the new APIs, but can't run in the old Flash player any more (I get crazy errors while it's loading the Flex framework like:

VerifyError: Error #1053: Illegal override of play2 in org.osmf.net.dynamicstreaming.DynamicNetStream.

ReferenceError: Error #1065: Variable _379fa43169660c76f131cadc0adfbfe8f347bd31d3ceec26a9cb2a56f0dda1f9_flash_display_Sprite is not defined.


Something like this should work:

var bitmapDatas:Vector.<BitmapData> = new <BitmapData>[new BitmapData(32,32,false, 0xFF0000)];

var MouseCursorDataClass:Class;
try {
    MouseCursorDataClass = getDefinitionByName("flash.ui.MouseCursorData") as Class;
}catch(e) {}
if(MouseCursorDataClass) {
    var cursorData = new MouseCursorDataClass();
    cursorData.data = bitmapDatas;
    Mouse["registerCursor"]("test", cursorData);
    Mouse.cursor = "Xmas";
}else {
    var customCursor=new Bitmap(bitmapDatas[0]);
    addChild(customCursor);
    stage.addEventListener(MouseEvent.MOUSE_MOVE, moveCursor);
}

function moveCursor(e) {
    customCursor.x=mouseX;
    customCursor.y=mouseY;
}

And in fact the MouseCursorData object gets created and is valid in 10.2, but for some reason the browser crashes when trying to call Mouse.registerCursor(). I'm publishing for 10.0 though, so probably if you publish for 10.2 the whole thing works properly on both 10 and 10.2.


if (Mouse["supportsNativeCursor"]) 
{
  // do stuff with MouseCursorData...
}

Notes:

  • This is equivalent to calling the property Mouse.supportsNativeCursor, but since supportsNativeCursor isn't supported either prior to 10.2 you need to check the property like this
  • Some devices may not support cursors even if they have 10.2 (Android tablets don't have cursors) -- so be aware of that too!
  • You may want to set this to a boolean because evaluating it probably gives a performance hit

Thanks to this video for this information. Skip to about 7:40 in the timeline :

http://www.youtube.com/watch?v=rtc3DYSuahI&feature=player_embedded#at=464

It's the video to accompany this article : http://everythingfla.com/quickies/native-mouse

Basically the solution is as follows:


I don't have a definitive answer on this, but here are some thoughts.

Have you tried building your base application for 10.0 in one SWF, putting the 10.2 code in another SWF that is compiled for 10.2, then doing a version detect and loading the 10.2 SWF if the Flash player is capable of the features in the sub-swf?

I am not sure if this would work, though. In the FP6, FP7, FP8 days, the root SWF controlled what features were really available, no matter what Flash player you were running in. For example, if the root was for FP6, a subswf for FP7, and running in Flash Player 8, you would still be (mostly) limited to FP6 functionality. Some FP7 features would work, but not all. It has been several years since I have had to do this, so I don't know how this works with the AS3 engine.

0

精彩评论

暂无评论...
验证码 换一张
取 消