views:

22

answers:

1

I'm trying to make a loader of a few photos (use FileReference). I get the warnings, but I do not know the reason for their appearance.

warning: unable to bind to property 'fr' on class 'Object' (class is not an IEventDispatcher) warning: unable to bind to property 'name' on class 'flash.net::FileReference' warning: unable to bind to property 'data' on class 'flash.net::FileReference' warning: unable to bind to property 'fr' on class 'Object' (class is not an IEventDispatcher) warning: unable to bind to property 'name' on class 'flash.net::FileReference' warning: unable to bind to property 'data' on class 'flash.net::FileReference'

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;
}
+1  A: 

This warnings occur because you try to bind to properties fr, FileReference.name and FileReference.data in your item renderer or somewhere. It may not bother you (don't know all you code) but to avoid them do the following:

Strong-typed data provider

Fill photos with objects of special class like:

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;
    }
}

Then replace the code:

var elem:Object = new Object;
elem.fr = FileReference(frList.fileList[i]);
elem.fr.load();
elem.fr.addEventListener(Event.COMPLETE,refreshThumb);
photos.addItem(elem);

With the following:

var elem:Photo = new Photo(frList.fileList[i]);
elem.fileReference.addEventListener(Event.COMPLETE,refreshThumb);
elem.fileReference.load();
photos.addItem(elem);

You should also change all the code that uses photos collection accordingly.

Maxim Kachurovskiy
Thanks Maxim, but I do not really understand how to use this class (Photo) in my project. I create and add a new AS class and imported into the project (import Photo;) and warnings were.
Astraport
Updated the answer.
Maxim Kachurovskiy