Apache flex FileReference中的警告-找不到原因
我正在尝试制作一些照片的加载程序(使用FileReference)。我收到了警告,但我不知道它们出现的原因 警告:无法绑定到类“Object”(类不是IEventDispatcher)上的属性“fr”) 警告:无法绑定到类“flash.net::FileReference”上的属性“name” 警告:无法绑定到类“flash.net::FileReference”上的属性“data” 警告:无法绑定到类“Object”(类不是IEventDispatcher)上的属性“fr”) 警告:无法绑定到类“flash.net::FileReference”上的属性“name” 警告:无法绑定到类“flash.net::FileReference”上的属性“data”Apache flex FileReference中的警告-找不到原因,apache-flex,file-upload,flash-builder,Apache Flex,File Upload,Flash Builder,我正在尝试制作一些照片的加载程序(使用FileReference)。我收到了警告,但我不知道它们出现的原因 警告:无法绑定到类“Object”(类不是IEventDispatcher)上的属性“fr”) 警告:无法绑定到类“flash.net::FileReference”上的属性“name” 警告:无法绑定到类“flash.net::FileReference”上的属性“data” 警告:无法绑定到类“Object”(类不是IEventDispatcher)上的属性“fr”) 警告:无法绑定到
import mx.events.CollectionEvent;
import flash.net.FileReferenceList;
import mx.collections.ArrayCollection;
[Bindable]
private var photos:ArrayCollection = new ArrayCollection;
private var frList:FileReferenceList = new FileReferenceList;
private function init():void
{
photos.addEventListener(CollectionEvent.COLLECTION_CHANGE,function():void
{
startUploadButton.enabled = (photos.length>0);
clearPhotosButton.enabled = (photos.length>0);
});
frList.addEventListener(Event.SELECT,addPhotos);
}
private function selectPhotos():void
{
var fileFilter:FileFilter = new FileFilter("Images jpeg","*.jpg;*.jpeg");
frList.browse([fileFilter]);
}
private function addPhotos(e:Event):void
{
for (var i:uint = 0; i < frList.fileList.length; i++)
{
var elem:Object = new Object;
elem.fr = FileReference(frList.fileList[i]);
elem.fr.load();
elem.fr.addEventListener(Event.COMPLETE,refreshThumb);
photos.addItem(elem);
}
}
private function refreshThumb(e:Event):void
{
photosList.invalidateList();
}
public function clearPhoto(data:Object):void
{
photos.removeItemAt(photos.getItemIndex(data));
photosList.invalidateList();
}
private function startUpload():void
{
photosProgressContainer.visible = true;
var request:URLRequest = new URLRequest();
request.url = "http://localhost/tempLoader-debug/upload.php";
var fr:FileReference = photos.getItemAt(0).fr;
fr.cancel();
fr.addEventListener(ProgressEvent.PROGRESS,uploadProgress);
fr.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,uploadComplete);
fr.upload(request);
}
private function uploadProgress(e:ProgressEvent):void
{
photosProgress.setProgress(e.bytesLoaded,e.bytesTotal);
}
private function uploadComplete(e:DataEvent):void
{
photos.removeItemAt(0);
photosList.invalidateList();
if (photos.length > 0)
startUpload();
else
photosProgressContainer.visible = false;
}
导入mx.events.CollectionEvent;
导入flash.net.FileReferenceList;
导入mx.collections.ArrayCollection;
[可装订]
私有var照片:ArrayCollection=新建ArrayCollection;
private var frList:FileReferenceList=newfilereferencelist;
私有函数init():void
{
photos.addEventListener(CollectionEvent.COLLECTION\u更改,函数():void
{
startUploadButton.enabled=(photos.length>0);
clearPhotosButton.enabled=(photos.length>0);
});
frList.addEventListener(Event.SELECT,addPhotos);
}
私有函数selectPhotos():void
{
var fileFilter:fileFilter=newfilefilter(“图像jpeg”,“*.jpg;*.jpeg”);
浏览([fileFilter]);
}
私人功能添加照片(e:事件):无效
{
for(变量i:uint=0;i0)
startupboad();
其他的
photoProgressContainer.visible=false;
}
出现此警告是因为您试图绑定到项目渲染器中或某处的属性fr
、FileReference.name
和FileReference.data
。这可能不会困扰您(不知道您的所有代码),但为了避免它们,请执行以下操作:
var elem:Photo = new Photo(frList.fileList[i]);
elem.fileReference.addEventListener(Event.COMPLETE,refreshThumb);
elem.fileReference.load();
photos.addItem(elem);
强类型数据提供程序
用特殊类别的对象填充照片
,例如:
public class Photo
{
public function Photo(fileReference:FileReference)
{
this.fileReference = fileReference;
}
public var fileReference:FileReference;
[Bindable("__NoChangeEvent__")] // __NoChangeEvent__ is a special name
public function get name():String
{
return fileReference.name;
}
[Bindable("__NoChangeEvent__")]
public function get data():*
{
return fileReference.data;
}
}
然后替换代码:
var elem:Object = new Object;
elem.fr = FileReference(frList.fileList[i]);
elem.fr.load();
elem.fr.addEventListener(Event.COMPLETE,refreshThumb);
photos.addItem(elem);
以下是:
var elem:Photo = new Photo(frList.fileList[i]);
elem.fileReference.addEventListener(Event.COMPLETE,refreshThumb);
elem.fileReference.load();
photos.addItem(elem);
您还应该相应地更改使用
照片的所有代码。谢谢Maxim,但我真的不知道如何在我的项目中使用此类(照片)。我创建并添加了一个新的AS类,并将其导入到项目(import Photo;)中,并删除了警告。