Reputation: 13
Could you give me some idea of how to give value to a variable from a function?
What I do is load the content of a txt, but I need that instead of feeding a dynamic text (that works), feed a variable that I can use outside the function. I want to give the content of the txt to the variable "textito" declared outside the function.
Any ideas?
The text "teet1" is only for a test, what I really need is to give value to the variable "textito" because I need to use it outside the function. Lo que ha
override public function SetData(xmlData:XML):void
{
for each (var element:XML in xmlData.children())
{
if (element.@id == "f0")
{
var textito:String
var f0 = [email protected]();
var f0A:String = f0.substr(-4);
var loader:URLLoader = new URLLoader(new URLRequest("C:/Users/Nicolás Agüero/Desktop/Test/" + f0));
loader.addEventListener(Event.COMPLETE, onFileLoaded);
function onFileLoaded():void
{
textito = loader.data;
}
teet1.text = textito;
}
}
}
Upvotes: 1
Views: 53
Reputation: 15881
Any variables that need global access should be declared outside of any functions.
Try a setup like this:
public var textito :String = "";
public var loader :URLLoader;
override public function SetData(xmlData:XML) :void
{
for each (var element:XML in xmlData.children())
{
if (element.@id == "f0")
{
var f0:String = [email protected]();
var f0A:String = f0.substr(-4);
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onFileLoaded);
loader.load( new URLRequest("C:/Users/Nicolás Agüero/Desktop/Test/" + f0) );
}
}
}
public function onFileLoaded(evt:Event) :void
{
textito = loader.data; //can also try... evt.data ...since the Event gives Loader its data.
teet1.text = textito;
}
Upvotes: 1