首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FileReference不会触发SELECT事件

FileReference不会触发SELECT事件
EN

Stack Overflow用户
提问于 2011-04-04 08:57:25
回答 2查看 654关注 0票数 0

我有以下代码。问题是在我通过浏览对话框选择一个文件后,SELECT和CANCEL事件都没有触发。

我有MacOS 10.6和FlashPlayer 10。

我做错了什么?

代码语言:javascript
复制
package
{

  import flash.display.Sprite;
  import flash.display.StageAlign;
  import flash.display.StageScaleMode;
  import flash.events.Event;
  import flash.events.MouseEvent;
  import flash.net.FileReference;
  import flash.net.FileFilter;
  import flash.net.URLRequest;

    public class loader2 extends Sprite
    {
      private var placeholder:Sprite;
      private var fileReference:FileReference;
      private var fileFilter:FileFilter;

      public function loader2()
      {
        super();
        this.stage.align = StageAlign.TOP_LEFT;
        this.stage.scaleMode = StageScaleMode.NO_SCALE;
        this.stage.addEventListener(MouseEvent.CLICK, clickHandler);
        this.init();
      }

      protected function init():void
      {
        this.placeholder = new Sprite();
        this.placeholder.graphics.beginFill(0x999999);
        this.placeholder.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
        this.placeholder.graphics.endFill();

        this.placeholder.useHandCursor = true;
        this.placeholder.buttonMode = true;

        this.addChild(placeholder);
      }

      protected function getHostName():String
      {
        var url:String = this.loaderInfo.loaderURL;
        var protocolIndex:Number = url.indexOf("://");

        var index:Number = url.indexOf("/", protocolIndex + 3);

        return url.substr(0, index);
      }

      protected function getUploadUrl():String
      {
        var host:String = this.getHostName();
        var action:String = this.loaderInfo.parameters["uploadurl"];

        if (action.length == 0)
          return host;

        return host.concat(action);
      }

      protected function clickHandler(e:MouseEvent):void
      {
        this.fileFilter = new FileFilter( "Any file", "*.*" );
        this.fileReference = new FileReference();

        this.fileReference.addEventListener(Event.SELECT, selectHandler);
        this.fileReference.addEventListener(Event.COMPLETE, completeHandler);

        this.fileReference.browse([this.fileFilter]);
      }

      protected function selectHandler(e:MouseEvent):void
      {
      }

      protected function completeHandler(e:MouseEvent):void
      {
      }
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-04-04 15:47:12

selectcomplete事件只是一个普通的Event,而不是MouseEvent。你的处理程序需要一个MouseEvent,所以当闪存试图运行它们时,你会得到一个错误。将处理程序中的事件参数类型更改为Event

代码语言:javascript
复制
protected function selectHandler(e:Event):void
// ...
protected function completeHandler(e:Event):void
票数 2
EN

Stack Overflow用户

发布于 2011-04-04 15:47:59

它能像在处理程序签名中选择错误的事件类型一样简单吗?MouseEvent而不是Event?

您可能还想添加以下监听器

代码语言:javascript
复制
this.fileReference.addEventListener(Event.CANCEL, cancelHandler);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5533634

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档