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

随声附和 提交于 2020-01-01 14:34:39

问题


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 versions 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.

回答1:


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.




回答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:




回答3:


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.



来源:https://stackoverflow.com/questions/4610528/optionally-use-flash-10-2-cursors-while-still-being-compatible-with-flash-10-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!