2011-04-04 17 views
0

次のコードがあります。問題は、ブラウズダイアログでファイルを選択しても、SELECTもCANCELイベントも発生しないということです。FileReferenceが起動しないSELECTイベント

私は私が間違って何をやっているの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; 
    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 
     { 
     } 
    } 
} 

答えて

2

selectcompleteイベントはMouseEventEvent普通ではありません。あなたのハンドラはMouseEventを期待しているので、Flashがそれらを実行しようとするとエラーが発生します。 Eventにあなたのハンドラでイベントパラメータの種類を変更します。

protected function selectHandler(e:Event):void 
// ... 
protected function completeHandler(e:Event):void 
+0

を追加するようなことがあり

が見えます:) –

+0

グレート発見、マイクを!私はあなたが正しいとほとんど確信しています。なぜ私はそれを逃したのだろうか。そういうわけでコピー貼りは悪いです)))私は今晩それを修正し、あなたの答えを受け入れるようにします。 – ILya

+0

それは動作します!ありがとうございました! – ILya

1

それは例えばハンドラの署名 に間違ったイベントの種類を選択するような単純なものでした。 EventではなくMouseEventですか?あなたはそれに私を打つようにあなたはまた、次のリスナー

this.fileReference.addEventListener(Event.CANCEL, cancelHandler); 
関連する問題