【问题标题】:How can i refer to an external function in an actionscript file - Flashbuilder如何在 actionscript 文件中引用外部函数 - Flashbuilder
【发布时间】:2012-01-27 04:19:35
【问题描述】:

我对 flashbuilder 有疑问:

我有一个带有 itemrenderer 的列表,它呈现(应该)可拖动的图像。 渲染的图像引用了一个在 actionscript 文件中声明的函数:文件夹 AS 中的 dragDrop.as。

名单:

<s:List id="imageList" width="139" height="438"
        dataProvider="{xmlListColl}"
        itemRenderer="itemRenderer.ImageRenderer"
        dragEnabled="true">

</s:List>

itemrenderer 渲染此图像并引用函数 doDrag:

<mx:Image width="100" height="70" maintainAspectRatio="true" 
          MouseDownEffect="AS.dragDrop.doDrag(event)"
          source="{data.@thumbnailImage}"/>

dragDrop.as 中的函数:

public function doDrag(event:MouseEvent):void
    {
        var img:mx.controls.Image = event.currentTarget as mx.controls.Image;
        var dragImg:mx.controls.Image = new mx.controls.Image();
        dragImg.source = img.source;

        var dsource:DragSource = new DragSource();
        dsource.addData(img, 'img');

        DragManager.doDrag(img, dsource, event, dragImg);
    }

但似乎该函数从未被调用...

parentdocument 和 outerdocument 似乎也不起作用(如果我将函数放在调用 itemrenderer 的文档中)

请帮忙!

【问题讨论】:

  • 您有包含dragDrops.as 文件的脚本标签吗?
  • 是的,死了:包括“AS/dragDrop.as”;

标签: apache-flex actionscript flash-builder


【解决方案1】:

这里有一些问题,但最终,您没有看到对该方法的引用,这意味着您的 dragDrop.as 文件不包括在内。

以下是一些建议:

  1. MouseDownEffect 替换为 mouseDown。您现在正在侦听“MouseEvent.MOUSE_DOWN”事件触发,而不是导致效果发生。 效果响应事件之间的区别在此处进行了描述,引用"Behaviors let you add animation and motion to your application when some user or programmatic action occurs, where a behavior is a combination of a trigger paired with an effect. A trigger is an action, such as a mouse click on a component ... An effect is a visible or audible change to the target component that occurs over a period of time, measured in milliseconds."
  2. 确保包含 dragDrop.as 文件。 Flex 3 与 Flex 4 处理 script 标签的方式不同。如果您没有包含或导入您的代码,那么它当然不会触发。
  3. include vs import 是个好问题。您可以“包含”定义方法、实例、常量等的代码。但是您可以“导入”已定义的类以供使用。由于您的方法是一个公共函数,它是否存在于一个类中?还是只存在于脚本文件中,在这种情况下,您应该删除访问器“public”
  4. 如果您希望实现拖放,我强烈建议您不要重新发明轮子并检查 Adob​​e 已经为组件实现的内容,包括 dragEnabled='true'dragMoveEnabled='true'。在这里查看它们:http://livedocs.adobe.com/flex/3/html/help.html?content=dragdrop_4.html http://livedocs.adobe.com/flex/3/html/help.html?content=dragdrop_1.html

以下是 Flex 3 脚本标签的示例:

&lt;mx:Script source="AS/dragDrop.as"/&gt;

以下是 Flex 4 脚本标签的示例:

<fx:Script source="AS/dragDrop.as"/>

这是有关如何将您想要的代码直接包含到 &lt;fx:Script&gt; 标记中的文档的链接:http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf61c8a-7ff4.html

【讨论】:

  • 用 mouseDown 替换 mouseDownEffect 有效。现在我有另一个问题:无法将渲染的项目拖出列表......我可以解决这个问题还是这不会简单地工作? (或者我应该打开一个新问题)
  • 好的,我解决了,只需将 dragMoveEnabled="true" 添加到列表中即可:) 谢谢!
  • 太棒了!不要忘记为任何需要注册“drop”事件的组件设置“dropMoveEnabled”。
  • 在组件上设置 dragEnter="dragAccept(event)" 和 dragDrop="dragDrop(event)" 似乎也可以解决问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-23
  • 2010-10-22
  • 2018-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多