0

我的 Flex 应用程序中有以下代码:

        protected function btn_select_image_clickHandler(event:MouseEvent):void {
            fileRef.addEventListener(Event.SELECT, Image_Select);
            fileRef.addEventListener(Event.COMPLETE, completeHandler);
            fileRef.browse(UploadFilter);
        }
        private function Image_Select(e:Event) : void {

            var fileSize:Number = Math.round( fileRef.size / 1024 );

            if ( fileSize <= 500 ) {

                var request:URLRequest  = new URLRequest( "http://gestor.domain.com/upload_image.php" );
                try {
                    fileRef.upload( request );
                } catch(error:Error) {
                    Alert.show( "Error loading image.", "Error" );
                }

            } else {
                Alert.show( "Image higher than 500Kb.", "Warning" );
            }
        }

        private function completeHandler(e:Event) : void {

            var file:FileReference = FileReference( e.target );
            Alert.show( "Data returned: "+file.data);
            if ( file.data != null ) {
                _filerefUploadMode = false;
                fileRef.load();
            }

        }

php 文件仅回显在 compleHandler 触发时要显示的字符串。

事实是 file.data 只返回null而我不知道发生了什么。

我失踪了吗?

4

1 回答 1

0

首先添加这个导入:

import flash.events.DataEvent;

然后添加这个监听器:

fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, uploadCompleteHandler);

然后使用这样的处理程序:

private function uploadCompleteHandler(e:DataEvent) : void 
{
    trace (e.data);
}
于 2013-08-25T20:34:25.090 回答