Groups | Blog | Home
all groups > flash actionscript > december 2006 >

flash actionscript : adding a variable to a listener


koomisan
12/3/2006 3:56:27 PM
hi
i am using the fileReference class, and i need to pass a variable to the
listeners

the functions i have at the moment is
_root["myBtn"+num].onRelease = function() {
var fileRef:FileReference = new FileReference();
fileRef.addListener(fileDownloadListener);
var url:String = "http://.......";
if (!fileRef.download(url)) {
trace("dialog box failed to open.");
}
};
fileDownloadListener.onProgress = function(file:FileReference,
bytesLoaded:Number, bytesTotal:Number, num):Void {
trace("onProgress with bytesLoaded: "+bytesLoaded+" bytesTotal:
"+bytesTotal);
}

what i need is to use the num variable in the fileDownLoadListener...
anyone know how to do that??
thanks

kglad
12/3/2006 4:47:40 PM
i don't think you can do that. you can use a work-around which should be
accurate unless someone is pressing buttons rapidly:



btnA = [];
for (var num = 0; num<3; num++) {
_root["myBtn"+num].numVar = num;
_root["myBtn"+num].onPress = function() {
_global.lastBtnPressedNum = this.numVar;
var fileRef:FileReference = new FileReference();
fileRef.addListener(fileDownloadListener);
var url:String = "http://.......";
if (!fileRef.download(url)) {
trace("dialog box failed to open.");
}
};
}
fileDownloadListener.onSelect = function(file:FileReference):Void {
btnA[file.name] = lastBtnPressedNum;
};
fileDownloadListener.onProgress = function(file:FileReference,
bytesLoaded:Number, bytesTotal:Number, num):Void {
trace("onProgress with bytesLoaded: "+bytesLoaded+" bytesTotal: "+bytesTotal);
trace(btnA[file.name]+" is your num variable's value");
};
koomisan
12/3/2006 5:25:23 PM
yea, managed to work around it
thanks
kglad
12/3/2006 5:45:12 PM
AddThis Social Bookmark Button