Groups | Blog | Home
all groups > flash actionscript > november 2007 >

flash actionscript : get array out of a function



schlafendes_faultier
11/2/2007 12:00:00 AM
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
kglad
11/2/2007 12:00:00 AM
you can return an array from a function:



function a1(x):Array{
var a:Array;
for(var i=0;i<x;i++){
a.push(i+1);
}
return a;
}

schlafendes_faultier
11/2/2007 12:00:00 AM
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
11/2/2007 12:00:00 AM
my error. use:



function a1(x):Array{
var a:Array = [];
for(var i=0;i<x;i++){
a.push(i+1);
}
return a;
}

schlafendes_faultier
11/2/2007 12:00:00 AM
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.


kglad
11/2/2007 12:00:00 AM
schlafendes_faultier
11/2/2007 3:28:07 PM
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
11/2/2007 3:56:07 PM
schlafendes_faultier
11/2/2007 4:01:56 PM
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
11/2/2007 7:33:14 PM
AddThis Social Bookmark Button