Log in

View Full Version : File Reference class and xml



punstc
08-27-2007, 11:06 PM
dealing with my xml mp3 player again looking through some topics and some help from someone on gotoandlearn forums i was told that the file reference class is what i need to use to force download from the xml file i used a code from a topic post to show how to use it and it tells you what all you need to change and such but i keep getting this error when i test my movie.

The class or interface 'flash.net.FileReference' could not be loaded.

this is my code to import it in



import flash.net.FileReference;

var myListener:Object = new Object();

myListener.onSelect = function(file:FileReference):Void {
trace("onSelect: " + file.name);
}

myListener.onCancel = function(file:FileReference):Void {
trace("onCancel");
}

myListener.onOpen = function(file:FileReference):Void {
trace("onOpen: " + file.name);
}

myListener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
}

myListener.onComplete = function(file:FileReference):Void {
trace("onComplete: " + file.name);
}

myListener.onIOError = function(file:FileReference):Void {
trace("onIOError: " + file.name);
}

var theFileRef:FileReference = new FileReference();
theFileRef.addListener(myListener);

punstc
08-28-2007, 12:44 AM
Never mind i have fixed that issue but it has only opened another.

i must have an error with my download button it opens the download dialog but it doesnt download anything i'm trying to use it with my xml so the xml file location attribute tells it where to get the file. heres what i have for my button


var url:String = "_global.songfile[this.id]";
_root["downloadbut"+i].onRelease = function() {
if(!theFileRef.download(url, "_global.songname[this.id].mp3")) {
trace("dialog box failed to open.");
} else {
trace("dialog box has open.");
}

Medyman
08-28-2007, 02:41 AM
One issue I see right away:

1.
var url:String = "_global.songfile[this.id]";

this variable would be better served if you declared it inside of the onRelease function. Also, did you do an eval of downloadbut and delcare the id property set to i (as you did for the lyrics button in the other thread)?

EDIT:
I also just noticed another thing.
Remove the quotes from the variable declaration. You're saying that url is LITERALLY equal to the string "_gloabl.songfile[this.id]" when you want it equal to just that expression.

punstc
08-28-2007, 03:00 AM
yes i have

eval("downloadbut"+i).id=i;

and i removed the quotes also

it gives me an undefined in the save menu now and still doesnt ownload anything.

punstc
08-28-2007, 03:03 PM
Quick update....i realized that i was setting an id to the wrong thing for the file reference so i set up an eval for the songname and songfile


eval(_global.songname[i]).id=1;
eval(_global.songfile[i]).id=1;


and this is my button code now



_root["downloadbut"+i].onRelease = function() {
var url:String = _global.songfile[this.id];
if(!theFileRef.download(url,_global.songname[this.id].mp3)) {
trace("dialog box failed to open.");
} else {
trace("dialog box has open.");
}

}


it still is returning an undefined though.

punstc
08-31-2007, 02:01 AM
I'm still working on this with out any success does anyone happen to have the slightest idea...I've been working on this player for over 2 weeks