如何更改 AS3 中的 DragManager 拒绝符号?

发布于 2024-12-11 01:48:02 字数 452 浏览 0 评论 0原文

我第一次在 flex4/as3 中开发拖放功能。我使用 DragManager 类,基本的拖放功能现在可以工作了。但是,如何更改当我将对象拖动到无法放置的区域时显示的红色小“拒绝光标”?

我可以在此处的样式规范中找到“rejectCursor”: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/managers/DragManager.html#styleSummary

但是我不知道如何在 AS3 中设置。我必须使用CSS吗?如果是的话,你能给我一个简单的例子吗?会很有帮助的!谢谢。

I'm working on a drag-n-drop functionality in flex4/as3, for the first time. I use the DragManager-class, and the basic drag-and-drop stuff works now. But, how do i change the little red "reject cursor" which is displayed when i drag objects over areas where i can't drop it?

I can find "rejectCursor" in the styles specification here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/managers/DragManager.html#styleSummary

But I have no idea about how to set in in AS3. Do i have to use css, and if yes, could you give me a quick example? Would be very helpful! Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三生一梦 2024-12-18 01:48:02

您需要使用 标记来声明全局样式:

<fx:Style>
    @namespace s "library://ns.adobe.com/flex/spark";
    @namespace mx "library://ns.adobe.com/flex/mx";

    mx|DragManager {
        rejectCursor: Embed('path/to/icon.pngORswf');
    }

</fx:Style>

Edit: 要从 AS3 类而不是从 MXML 执行此操作,您可以使用:

import mx.core.FlexGlobals;
import mx.styles.IStyleManager2;
import mx.styles.CSSStyleDeclaration;

[Embed('path/to/icon.pngORswf')]
private var rejectCursor:Class;

var mgr:IStyleManager2 = FlexGlobals.topLevelApplication.styleManager;
var selector:String = "mx.managers.DragManager";
var decl:CSSStyleDeclaration = mgr.getStyleDeclaration(selector);
if (!decl)
    decl = new CSSStyleDeclaration(selector);
decl.setStyle("rejectCursor", rejectCursor);
mgr.setStyleDeclaration(selector, decl, false);

You need to use the <fx:Style> tag to declare the global style:

<fx:Style>
    @namespace s "library://ns.adobe.com/flex/spark";
    @namespace mx "library://ns.adobe.com/flex/mx";

    mx|DragManager {
        rejectCursor: Embed('path/to/icon.pngORswf');
    }

</fx:Style>

Edit: To do this from an AS3 class instead of from MXML, you would use:

import mx.core.FlexGlobals;
import mx.styles.IStyleManager2;
import mx.styles.CSSStyleDeclaration;

[Embed('path/to/icon.pngORswf')]
private var rejectCursor:Class;

var mgr:IStyleManager2 = FlexGlobals.topLevelApplication.styleManager;
var selector:String = "mx.managers.DragManager";
var decl:CSSStyleDeclaration = mgr.getStyleDeclaration(selector);
if (!decl)
    decl = new CSSStyleDeclaration(selector);
decl.setStyle("rejectCursor", rejectCursor);
mgr.setStyleDeclaration(selector, decl, false);
云归处 2024-12-18 01:48:02

通常在 AS3 中,您可以像这样在 Flex 组件上设置样式:

UIComp.setStyle('styleName',newValue);  

但是,由于 DragManager 不扩展 UIComponent,因此不存在 setStyle 方法。从这里开始,我有点猜测。

如果你深入研究代码;你会发现 DragProxy 类和一个 showFeedback 方法,其中有一个如下所示的片段:

var styleSheet:CSSStyleDeclaration = styleManager.getMergedStyleDeclaration("mx.managers.DragManager");
newCursorClass = styleSheet.getStyle("rejectCursor");

因此,你可以尝试在 DragProxy 的实例上设置该样式;但您需要访问 DragProxy 实例。看起来您需要使用 mx_internal 执行此操作:

import mx.core.mx_internal;
use mx_internal

然后您可以执行以下操作:

var myDragProxy : DragProxy = DragManager.dragProxy()
dragProxy.setStyle('rejectCursor', newValue);

Generally in AS3 you can set a styles on a Flex Component like this:

UIComp.setStyle('styleName',newValue);  

However, since DragManager does not extend UIComponent the setStyle method does not exist. From here, I'm guessing a bit.

If you dig into code; you'll find the DragProxy class, and a showFeedback method, which has a segment like this:

var styleSheet:CSSStyleDeclaration = styleManager.getMergedStyleDeclaration("mx.managers.DragManager");
newCursorClass = styleSheet.getStyle("rejectCursor");

So, you could try setting that style on the instance of the DragProxy; but you'll need access to the DragProxy instance. It looks like you need to use mx_internal do that:

import mx.core.mx_internal;
use mx_internal

Then you can do something like this:

var myDragProxy : DragProxy = DragManager.dragProxy()
dragProxy.setStyle('rejectCursor', newValue);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文