Skip to main content
November 2, 2007
Question

get array out of a function

  • November 2, 2007
  • 8 replies
  • 386 views
hello.

i've an array and in a function and i don't know how to get it out of the funktion because i want to use it in a dynamic way. »return« does not work. i try it last night for 3 hours and i find no way.

please help me an sorry for my teribble english, i'm a german one.

bernhard
This topic has been closed for replies.

8 replies

kglad
Community Expert
Community Expert
November 2, 2007
you're welcome.
November 2, 2007
hm. changing this, the cmpiler tell me that at the end of the function nothing is giving back.
so, my battery is empty and it a chance for me to get home and read again in the documention antil my eyes stop working.

anyway, thank you for your words.
kglad
Community Expert
Community Expert
November 2, 2007
why do you have return type "void". that should be "Array".
November 2, 2007
so i've do that. in one way it's great, because in my dynamic work now the xml is not loadet again and again. in the other way - the compiler is still telling me the same word's like befor.

maybe there is something more wrong in my code. here he is:

function xmlLoaded(event:Event):void
{
myXML = XML(myLoader.data);
}
function namen(event:MouseEvent):void
{
// ERSTELLEN EINES MEHRDEMINSIONALEN ARRAYS, INDEM DIE XML-DATEN EINGELESEN WERDEN
var arrayFromXML:Array = [];
// variabel zum identifizieren der oberen dimension des arrays
var rein:uint = 0;
for each (var knoten in myXML.hallo)
{
arrayFromXML[rein]= [(knoten.number), (knoten.nummer), (knoten.titel)]; // der erste eintrag ist nur für die sortierung!
rein = rein + 1;
}
trace(arrayFromXML[1][1]);
return arrayFromXML;
...
...
...

kglad
Community Expert
Community Expert
November 2, 2007
your xml data must be completely loaded before you call the function that returns arrayFromXML. ie, if that code is in your xml.onLoad method, it will fail.
November 2, 2007
it is not working. my code look a little different, because it's an »LotOfDimension« - array. here is the part of my code for filling it.

var arrayFromXML:Array = [];
// variabel zum identifizieren der oberen dimension des arrays
var rein:uint = 0;
for each (var knoten in myXML.hallo)
{
arrayFromXML[rein]= [(knoten.titel), (knoten.nummer), (knoten.titel)]; rein = rein + 1;
}
return arrayFromXML;


and, thank you for your talking with me.

November 2, 2007
yes, that is what i tryed. i get a return in the compiler, he says the thing giving back is not allowed to be defined. (whit an 1051-number. my compiler talks german to me.)
kglad
Community Expert
Community Expert
November 2, 2007
my error. use:

kglad
Community Expert
Community Expert
November 2, 2007
you can return an array from a function: