Flash Question
- Started
- Last post
- 10 Responses
- st33d
Surely someone knows how to do this:
In Java I can stick any object in an array.
In Python I can stick any object in a list.
Why can't I do either of these in Flash!?! All I've found is tutorial after tutorial on strings and numbers in arrays. I'm trying to make lists of Actionscript2.0 classes here. AARGH!!!
- UndoUndo0
stick the name of the object in the array
- st33d0
I'm making a stack of objects from a custom class.
for(i = 0; i < 100; i++){
var ["dave" + String(i)]:Dave = new Dave();
}Throws a syntax error. I'm getting no love trying to batch instance a class here. I could stick the name in an array but I can't even name it to begin with.
- blaw0
not as2.0, but:
http://rafb.net/paste/results/8z…
- Hello-Sexy0
your first question doesnt match the logic in your last post.
are you trying to declare a bunch of new Daves in one array?
or are you just trying to declare a bunch of new Daves at once?
- enjine0
you're talking about a keyed array, which is completely different.
plus your example is totally whack.
try something more like this:
var arr:Array = new Array();
for(var i=0; i
- enjine0
aww shit it cut off my code
var arr:Array = new Array();
for(var i=0; i
- enjine0
damn again...
at any rate, within the for loop just make a temporary variable then push it into the array
var tempObj = new Dave();
arr.push(tempObj)or instead of using the push method, just use the iterator and brackets: arr[i] = tempObj
- st33d0
To Hello-Sexy -> My logic is fine from a Java background when using Vector() and lists[] in Python. You can put any old shit in them, but to begin with in Flash that doesn't seem to be the case.
But the push method works great, thanks muchly. Just like Python list.append()
var test_array:Array=new Array();
for(var i=0;i
- Hello-Sexy0
perhaps i should rephrase... the code you had confused me. it could have been an invalid attempt at either method i mentioned earlier; glad you got it figured out...
- st33d0
Whoo hoo!
http://www.robotacid.com/misc/Al…
Well that only took me 6 hours to figure out. (Pure code animation)
Jesus I'm retarded.