I'm getting the following error:
TypeError: Error #2007: Parameter text must be non-null.
at flash.text::TextField/set text()
at Function/<anonymous>()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
This is my code:
myButton.addEventListener(MouseEvent.CLICK, onClickNewFB);
function onClickNewFB(e:MouseEvent):String{
var req:URLRequest=new URLRequest(e.target.name+".txt");
var infoLoader:URLLoader=new URLLoader();
var myInfoLoader:String;
infoLoader.load(req);
myInfoLoader=infoLoader.data;
infoLoader.addEventListener(Event.COMPLETE, loadFeedbackText);
//OSD_feedbackText.text=e.target.name;
return myInfoLoader;
function loadFeedbackText(e:Event):void{
//OSD_feedbackText.text=infoLoader.data;
OSD_feedbackText.text=myInfoLoader;
}
trace(myInfoLoader);
}
How do I fix this? I'm sure I have an incorrect order of operations and I probably shouldn't declare a function within a function but I don't know how else to approach the solution. Any help is much appreciated.
-markerline
Now I'm getting #1067: Implicit coercion of a value of type String to an unrelated type flash.net:URLRequest . . for the following code:
function onClickNewFB(e:MouseEvent):String{
var req:URLRequest=new URLRequest(e.currentTarget.name+".txt");
var infoLoader:URLLoader=new URLLoader();
var myInfoLoader:String;
var myStr:String= new String();
var req2:URLRequest=new URLRequest(myStr);
myStr=e.target.name+".txt";
infoLoader.load("\""+req2+"\"");
trace(myStr);
myInfoLoader=infoLoader.data;
infoLoader.addEventListener(Event.COMPLETE, loadFeedbackText);
//OSD_feedbackText.text=e.target.name;
return myInfoLoader;
function loadFeedbackText(e:Event):void{
//OSD_feedbackText.text=infoLoader.data;
OSD_feedbackText.text=myInfoLoader;
}
trace(myInfoLoader);
}
The error is being thrown on this line:
infoLoader.load("\""+req2+"\"");
I can trace the results of myStr and it gives me the correct filename. But I cannot seem to pass this filename into my infoLoader.load() method. What do I do next?
-markerline
I fixed the code in the following way:
function onClickNewFB(e:MouseEvent):String{
var req:URLRequest=new URLRequest(e.currentTarget.name+".txt");
var infoLoader:URLLoader=new URLLoader();
var myInfoLoader:String;
var myStr:String= new String();
var req2:URLRequest=new URLRequest('\"'+myStr+'\"');
myStr=e.target.name+".txt";
infoLoader.load(req2);
trace(myStr);
myInfoLoader=infoLoader.data;
infoLoader.addEventListener(Event.COMPLETE, loadFeedbackText);
//OSD_feedbackText.text=e.target.name;
return myInfoLoader;
function loadFeedbackText(e:Event):void{
//OSD_feedbackText.text=infoLoader.data;
OSD_feedbackText.text=myInfoLoader;
}
trace(myInfoLoader);
}
but now I'm getting Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file: <<filename>>
where <<filename>> is an actual location on my computer
at FlashFileName::MainTimeline/onClickNewFB()
. . . I am at a loss. If I can pass the string to the URL Request and the file exists in my directory, then why am I getting an IO error?
P.S. I should note that <<filename>> actually appears as ///C|Users/[username]/[directory]/"FILENAME.txt" with the double quotes around the filename. I also had to put myStr=e.target.name+".txt"; above the previous line to get this far. If I change the URLRequest to new URLRequest(myStr) then I don't even get an IO Stream error. I get
TypeError: Error #2007: Parameter text must be non-null.
at flash.text::TextField/set text()
at Function/<anonymous>()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
????
-markerline
Message was edited by: markerline
Yes, kglad. I'm well aware of the benefits of relative paths. I was actually simply passing the filename as it stands without directory information but the output console gave me the full path of the filename, which means it's looking in the right place, but it's wrapping the name of the file (not the entire path) with quote marks. I have since changed my file to not use this scripted method for identifying which file to read and have built the text content into movie clips and accessed the movie clips from frame labels on the timeline. However I would still like to know how to do it the scripted way for the benefit of me learning how to properly apply this method and for the benefit of others wishing to do the same.
-markerline
North America
Europe, Middle East and Africa
Asia Pacific