Flash 文件引用不';t火灾选择事件
我有以下代码。问题是,在通过浏览对话框选择文件后,不会触发选择或取消事件 我有MacOS 10.6和FlashPlayer 10 我做错了什么Flash 文件引用不';t火灾选择事件,flash,actionscript-3,filereference,Flash,Actionscript 3,Filereference,我有以下代码。问题是,在通过浏览对话框选择文件后,不会触发选择或取消事件 我有MacOS 10.6和FlashPlayer 10 我做错了什么 package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.events.MouseEvent;
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
{
}
}
}
选择
和完成
事件只是一个正常的事件
,而不是鼠标事件
。您的处理程序需要一个MouseEvent
,因此当Flash试图运行它们时,您会收到一个错误。将处理程序中事件参数的类型更改为event
:
protected function selectHandler(e:Event):void
// ...
protected function completeHandler(e:Event):void
选择
和完成
事件只是一个正常的事件
,而不是鼠标事件
。您的处理程序需要一个MouseEvent
,因此当Flash试图运行它们时,您会收到一个错误。将处理程序中事件参数的类型更改为event
:
protected function selectHandler(e:Event):void
// ...
protected function completeHandler(e:Event):void
这会像在处理程序签名中选择错误的事件类型那样简单吗 用MouseEvent代替Event 您还可以添加以下侦听器
this.fileReference.addEventListener(Event.CANCEL, cancelHandler);
这会像在处理程序签名中选择错误的事件类型那样简单吗 用MouseEvent代替Event 您还可以添加以下侦听器
this.fileReference.addEventListener(Event.CANCEL, cancelHandler);
看起来你赢了我:)太好了,迈克!我几乎可以肯定你是对的。我想知道为什么我错过了它。这就是为什么复制粘贴是邪恶的。)今晚我会设法修复它,然后接受你的回答。看起来你比我先做到了:)很好的发现,迈克!我几乎可以肯定你是对的。我想知道为什么我错过了它。这就是为什么复制粘贴是邪恶的。)今晚我会尝试修复它,然后接受你的答案。