Simply-linked list in Flash MX.. Can it be done?

I’d like to know if there’s a way of building a simply-linked list in Flash MX.

Suppose this is my class:

function Node(myear, mvalue) {
	this.year = myear;
	this.value = mvalue; = ?????;

I want to create a structure this way:

  1. How do I define the “next” property in the Node class so as to point to another Node object ?
  2. When creating an instance of my Node class with the new operator, how do I link it to the list ? I mean, can I move through the linked list and insert the new node at the end ? How do I move through the list ? Do I have pointers (or similar) ? Can you show me how to manage them in ActionScript?

I’m wondering if this can be done in Flash MX. If not, is there a way of “emulating” this structure with arrays, objects and/or whatever ?

Thank you in advance,


I’m a bit confused by your question, so please forgive me if I fail to help.

On your first question.

I’m not sure which value you’re trying to increase but, one way to do it is to declare a counter variable on the main timeline (frame 1 for example).


then, just increase the value of counter wherever it is necessary, perhaps using counter++; which is the same as saying counter=counter+1;

on the second question: Sounds like you need an array.

myArray = New Array();

then, you could push your values into the array

Myarray.push(next + counter);

or something of the sort. Again, a little hard to explain since I am not sure of exactly what you would like to accomplish.

Hope it helped a little!

Thank you for your explanation. In fact, what I need to achieve is a little bit more complicated than this.

I need to create a linked list of custom objects (Node objects) like those made in C, Pascal, etc. I’m just trying to find out if it’s possible not to use arrays but lists, where each node points to the next one.

Example code in Pascal:
[COLOR=blue]nodeptr = ^node;[/COLOR]
nodetype = record
myinfo: integer;
[COLOR=red]nextnode: nodeptr;[/COLOR]

I should define something like that in Flash.
So, in the class definition I need to define a link to an object of the same cl**** it is recursive.

function Node(myear, mvalue) {
this.year = myear;
this.value = mvalue;
[COLOR=green][/COLOR] = ???;

[COLOR=green][/COLOR] corresponds to the [COLOR=red]nextnode: nodeptr;[/COLOR] in the Pascal example. I should define a pointer to an object of its own class…, but I don’t know how to do it… :frowning: And I also don’t know how to move through the linked list once it’s created.

Did I make myself understood now or is it still confusing ? Sorry about my english, I’m not used to writing or speaking english so perhaps you don’t understand me… :frowning:

All your help is very much appreciated :slight_smile:

Hey, man forget it. This is not C :P. Unless you know how they are coded, I don’t think there’s a way to use pointers in Flash MX. It’s not very useful either, especially in your case, because you can declare an array, and you don’t have to declare its size, so you can just push in your stack, as Inigo said.

OR maybe you can create your class (#initclip and registerClass things), but I don’t know how you can access the memory from Flash.

Good luck.

pom :asian:

Yes, I supposed this was not like C but just in case…
OK, I’ll try with an array :-\
Thanks for your help guys =)


you could hack a solution with an array that contains pointers to each node, and define “next” as a method to retrieve the following item of the array:

_root.nodeArray = []

function Node(myear, mvalue) {
   this.year = myear;
   this.value = mvalue;
} = function(){
   var p = _root.nodeArray.getPlace(this);
   if(p>0){ return(_root.nodeArray[p+1]); }
   else{ return(null); }

Array.prototype.getPlace = function(targ){
   var l = this.length;
   while(l--){ if(this[l] == targ) return(l); }

that’s untested but should do the trick. and it will still work if you decide to shuffle the array around later.

Great! I’ll try this code!
Millions of thanks ! :slight_smile: