我如何在actionscript文件中引用外部函数--Flashbuilder

时间:2011-12-24 02:21:22

标签: flex actionscript flash-builder

我遇到了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的文档中)

请帮助!

1 个答案:

答案 0 :(得分:0)

这里有一些问题,但最终,你没有看到对该方法的引用,这意味着你的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处理脚本标记的方式不同。如果您不包含或导入代码,那么它当然不会触发。
  3. 包含 vs 导入是一个很好的问题。您可以“包含”代码,这些代码是方法,实例,常量等的定义。但您可以“导入”定义的类以供使用。由于您的方法是公共函数,它是否存在于类中?或者它只是存在于脚本文件中,在这种情况下,您应该删除访问者“public”
  4. 如果您正在寻求实施拖放功能,我强烈建议您不要重新发明轮子并查看Adobe已经为组件实施的内容,包括 dragEnabled ='true'和的 dragMoveEnabled = '真'即可。在这里查看它们: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
  5. 以下是 Flex 3 脚本代码的示例:

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

    以下是 Flex 4 脚本代码的示例:

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

    这是指向如何直接在<fx:Script>代码中添加您喜欢的代码的文档的链接:http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf61c8a-7ff4.html

相关问题